我有一个curl命令,它返回单行,但有很长的响应体。并且需要搜索特定的字符串并打印结果。
例如,下面是curl的输出。我可以使用bash脚本打印centos的状态值是"true"吗?或者我应该使用不同的脚本/程序语言?脚本基本上应该输出为state=true。注意,在输出
中有两个"状态"值~]# curl -v -k -u test:test https://myurl.com/api/state
"name":"centos","type":"disc","state":true},{"partitions":5},"auth_mechanisms": [{"name":"PLAIN","description":"PLAIN authentication"}], [{"name":"suse","type":"ram","state":true}]
您可以尝试这个组合的sed
命令,
sed 's/},/'n/g' file | sed -nr '/centos/ s/.*:(.*)$/'1/p'
例子:
$ echo '"name":"centos","type":"disc","state":true},{"partitions":5},"auth_mechanisms": [{"name":"PLAIN","description":"PLAIN authentication"}], [{"name":"suse","type":"ram","state":true}]' | sed 's/},/'n/g' | sed -nr '/centos/ s/.*:(.*)$/'1/p'
true