在awk中使用两个野战矛 [英] Use two field spearators in awk
本文介绍了在awk中使用两个野战矛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用bash解析这样的字符串
I am trying to parse a string like this with bash
OPS |all|1234|ip:port1|name|state|number|id|phone=123;zip=123;state=AB;city=seattle .
OPS |all|1234|ip:port2|name|state|number|id|phone=123;zip=123;state=AB;city=spokane .
我想要这样的输出
seattle | ip port1
spokane | ip port2
我试图与此一起使用awk
I was trying to use awk with this
awk -F'|' '{ n = split($4,array,"|"); printf "%s, %s\n", $4, array[n] }' file.txt
但是它没有打印我想要的细节
but its not printing the details that I want
推荐答案
使用-F
和[]
设置多个字段分隔符.
Use -F
and []
to set multiple field separators.
awk -F '[|:= ]' '{print $14,"|",$4,$5}' file
输出:
seattle | ip port1
spokane | ip port2
这篇关于在awk中使用两个野战矛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文