Post

linux awk filter using pattern1 or pattern2

linux awk filter using pattern1 or pattern2

AWK’s pipe | as an OR operator for field splitting is one of those things that isn’t obvious until you see it. This is handy when your delimiter isn’t a single character — you can split on multiple patterns at once and pull out exactly the fields you need.

  • Use pipe to add multiple filter
1
2
3
$ echo "1a2b3a" | awk -F 'a|b' '{print $1 " " $2 " " $3}'

1 2 3
This post is licensed under CC BY 4.0 by the author.