我正在linux上运行geoiplookup命令,该命令提供以下内容:
[root@localhost temp]$ geoiplookup 8.8.8.8
GeoIP Country Edition: US, United States
GeoIP City Edition, Rev 1: US, N/A, N/A, N/A, 38.000000, -97.000000, 0, 0
GeoIP City Edition, Rev 0: US, N/A, N/A, N/A, 38.000000, -97.000000
GeoIP ASNum Edition: AS15169 Google Inc.
我希望输出在同一行上,并已尝试:
[root@localhost temp]$ geoiplookup 8.8.8.8 | sed '2,3d' | sed 's/^.*: /,/g' | sed '$!{:a;N;s/\n/\t/;ta}' | awk -F ',' '{print $4","$2}'
AS15169 Google Inc.,US
很抱歉让你误会了。我想用更简单的方法保持国家代码和ASNum作为输出行。
就像“AS15169美国谷歌公司”
最佳答案
geoiplookup 8.8.8.8 | awk '/^GeoIP Country/{ sub(/,*$/, "", $4); c = $4; } sub(/^GeoIP ASNum Edition: /, ""){ print $0 "," c }'
预期产量:
AS15169 Google Inc.,US
编辑:
sub
就足够了。不需要去gsub
。关于linux - Linux:将输出合并为一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24772751/