O caminho certo com a ferramenta jq
para documentos JSON válidos:
Amostra file1.json
:
{
"socal": "https://xxx.xxxxx.xxx",
"ip": "xxx.xxx.xxx.xxx",
"tire_id": "213275925375485",
"client": {
"platform": "xx",
"clientID": "xxxxx",
"serviceID": "xxxxx",
"service_id": "XXXX",
"vendor": "default"
},
"locale": "en_US",
"cdc": {
"appID": "233262274090443",
"isdel": "ORdiZBMAQS2ZBCnTwZDZD"
},
"attachments": {
"output": "attachments",
"public": false
}
}
Amostra file2.json
:
{
"socal": "https://xxx.xxxxx.xxx",
"ip": "xxx.xxx.xxx.xxx",
"tire_id": "1305436516186552",
"client": {
"platform": "xx",
"clientID": "xxxxx",
"serviceID": "xxxxx",
"service_id": "XXXX",
"vendor": "default"
},
"locale": "en_US",
"cdc": {
"appID": "1164562920689523",
"isdel": "ORdiZBMAQS2ZBCnTwZDZD"
},
"attachments": {
"output": "attachments",
"public": false
}
}
E a solução em si:
jq -r 'input_filename + " tire_id: \(.tire_id) appID: \(.cdc.appID)"' file*.json
A saída:
file1.json tire_id: 213275925375485 appID: 233262274090443
file2.json tire_id: 1305436516186552 appID: 1164562920689523