Linux 如何使用shell脚本打印解析Json
如何使用grep awk打印,以便从下面的字符串打印成功Linux 如何使用shell脚本打印解析Json,linux,shell,Linux,Shell,如何使用grep awk打印,以便从下面的字符串打印成功 {“身份”:“2320147”,“身份验证”:“成功”}使用GNU awk: echo“{”identity:“2320147”,“authentication:“success”}”|awk-F“[:}]”“{print$3}” 输出: success使用jq test='{"identity":"2320147","authentication":"success"}' $ jq -r '.authentication' <&
{“身份”:“2320147”,“身份验证”:“成功”}使用
GNU awk
:
echo“{”identity:“2320147”,“authentication:“success”}”|awk-F“[:}]”“{print$3}”
输出:
success
使用jq
test='{"identity":"2320147","authentication":"success"}'
$ jq -r '.authentication' <<< $test
success
看起来使用python或其他工具比使用shell命令更容易解析。看见
$ jq -h
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
...
-r output raw strings, not JSON texts;
...