在shell中,我有一个要求,我必须读取以下格式的JSON响应:
{ "Messages": [ { "Body": "172.16.1.42|/home/480/1234/5-12-2013/1234.toSort", "ReceiptHandle": "uUk89DYFzt1VAHtMW2iz0VSiDcGHY+H6WtTgcTSgBiFbpFUg5lythf+wQdWluzCoBziie8BiS2GFQVoRjQQfOx3R5jUASxDz7SmoCI5bNPJkWqU8ola+OYBIYNuCP1fYweKl1BOFUF+o2g7xLSIEkrdvLDAhYvHzfPb4QNgOSuN1JGG1GcZehvW3Q/9jq3vjYVIFz3Ho7blCUuWYhGFrpsBn5HWoRYE5VF5Bxc/zO6dPT0n4wRAd3hUEqF3WWeTMlWyTJp1KoMyX7Z8IXH4hKURGjdBQ0PwlSDF2cBYkBUA=", "MD5OfBody": "53e90dc3fa8afa3452c671080569642e", "MessageId": "e93e9238-f9f8-4bf4-bf5b-9a0cae8a0ebc" } ] }
在这里,我只关心“ Body”属性值。我做了一些不成功的尝试,例如:
jsawk -a 'return this.Body'
要么
awk -v k="Body" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}
但这还不够。谁能帮我这个?
jq在命令行上有用于解析json的代码:
jq
jq '.Body'
访问此以获得jq:https://stedolan.github.io/jq/