I have a output of json format as below
{
"ip": "0.0.0.0",
"hostname": "No Hostname",
"city": "Beijing",
"region": "Beijing Shi",
"country": "CN",
"loc": "39.9289,116.3883",
"org": "AS55967 Beijing Baidu Netcom Science and Technology Co., Ltd."
}
i need values of country and city as below
CN Beijing
i have used below jq command and sed command to display country but dont know how to display city as another column.
jq
curl -s ipinfo.io/0.0.0.0 | jq '.country'
sed
curl -s ipinfo.io/0.0.0.0 | sed '/country/!d' | sed s/\"country\":\ //g | sed 's/\"//g' | sed 's/\,//g'
The output of this country and city columns should be added to 4th & 5th column of another csv file sample below
2016-03-29 00:05:23 0.0.0.0 CN Beijing 10.0.0.197
2016-03-29 00:56:37 1.1.1.1 FR France 10.0.1.117
2016-03-29 00:57:20 2.2.2.2 FR France 10.0.0.197
jq -j '.country, " ", .city, "\n"'? Thenpaste other_file jq_output?