1
blackeeper 2022-04-12 15:59:22 +08:00
第一步,提取 url 。url=$(echo "listen url is http://127.0.0.1:56099/AbcDEfJ-lr4=/" |grep 'http://' |sed 's#^.*\( http:.*\)#\1#g')
第二步,替换 json file 内容。sed "s/http.*/$url\"/g" file.json |
2
AirTag OP |
3
ysc3839 2022-04-12 18:10:16 +08:00
@blackeeper 需要这么麻烦吗? grep 就可以直接用正则表达式匹配
``` $ echo 'listen url is http://127.0.0.1:56099/AbcDEfJ-lr4\=/' | grep -Po 'http.+' http://127.0.0.1:56099/AbcDEfJ-lr4\=/ ``` 保险一点可以带上前面的字符串 ``` echo 'listen url is http://127.0.0.1:56099/AbcDEfJ-lr4\=/' | grep -Po 'listen url is \Khttp.+' http://127.0.0.1:56099/AbcDEfJ-lr4\=/ ``` |
4
AirTag OP |
6
Cusmate 2022-04-13 12:01:59 +08:00
如果 shell 的输出格式不变就用 awk 提取
shell 命令 | awk '{print "{\"config\":[{\"listen\":"$4"\"}]}"}' |