This question already has an answer here:
- AWK multiple delimiter 6 answers
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 .
I want output like this
seattle | ip port1
spokane | ip port2
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
Use
-F
and[]
to set multiple field separators.Output: