我需要使用正则表达式解析JSON数组。我的JSON如下:
"keys": [
{
"host": "example.com"
},
{
"host": "example.net"
}
]
我需要获取两个主机值。
当你想要提取文本时,grep
是你的朋友:
grep -Po '(?<="host": ")[^"]*' myjsonFile
例如:
kent$ echo '"keys": [
{
"host": "example.com"
},
{
"host": "example.net"
}
]'|grep -Po '(?<="host": ")[^"]*'
example.com
example.net
/"host":\s"(.*?)"/
{}
中);你可以使用jq -r '.keys[] | .host'
。 - jfs