【发布时间】:2016-04-05 14:04:16
【问题描述】:
我有一个json格式的输出如下
{
"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."
}
我需要如下国家和城市的值
CN Beijing
我使用下面的 jq 命令和 sed 命令来显示国家,但不知道如何将城市显示为另一列。
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'
该国家和城市列的输出应添加到下面另一个 csv 文件示例的第 4 列和第 5 列
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"'?然后paste other_file jq_output?