3

Find and Replace in multiple fields using awk

view full story
linux-howto

http://www.unix.com – Hi, Say I have a record "1|22| | |". In which the third and fourth fields are <space> alone. I have to replace the <Space> with <null>. Input: Code: "1|22| | |" --> "1|22|<space> |<space> |" Expected output: Code: "1|22|||" --> "1|22|<null> |<null>|" I tried: Code: echo "1|22| | |" | awk -F '|' -v v1=" " -v v2="" 'BEGIN{OFS="|";}{gsub(v1,v2,$3);print}' echo "1|22| | |" | awk -F '|' -v v1=" " -v v2="" 'BEGIN{O (HowTos)