我有以下awk代码:
ip addr | grep -v '1: lo:' | grep -v '127.0.0.1' | awk '/^[0-9]+:/ {sub(/:/,"",$2); iface=$2 } /^[[:space:]]*link\/ether / {mac=$2} /^[[:space:]]*inet / {split($2, if_arr, "/"); print iface "," if_arr[1] "," mac}'
输出如下:
eth0,10.53.55.22,00:51:56:9g:2f:e2
但我需要像这样的输出(双引号):
"eth0","10.53.55.22","00:51:56:9g:2f:e2"
答案 0 :(得分:2)
只需设置/使用OFS
,如果您已经使用了awk,则无需使用grep:
ip addr |
awk -v OFS='","' '/1: lo:|127.0.0.1/{next} /^[0-9]+:/... print "\"" iface, if_arr[1], mac "\""}'
尽管你使用的是什么工具,但你可能应该逃避.
中的每个127.0.0.1
。
答案 1 :(得分:1)
从
更改打印声明'b
到
print iface "," if_arr[1] "," mac