Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何使用shell脚本打印解析Json_Linux_Shell - Fatal编程技术网

Linux 如何使用shell脚本打印解析Json

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' <&

如何使用grep awk打印,以便从下面的字符串打印成功


{“身份”:“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;
...