Awk tutorial: awk -F and awk BEGIN{ FS … }

Usually, when I use awk for text processing, I prefer to use the awk -F option for text field separation.

Of course, we can also use the combination of BEGIN and FS to achieve the same goal.

Let’s take a look at their use examples.

awk -F

➜ echo "abc:123:dffff:xxo" | awk -F":" '{print $1}'

awk ‘BEGIN{FS=”:”}’

➜ echo "abc:123:dffff:xxo" | awk 'BEGIN{FS=":"}{print $1}'

Related post

awk command tutorial in linux/unix with examples and use cases
Awk tutorial: awk merge files base on the keyword
AWK tutorial: awk custom function and awk example
Awk tutorial: find and kill process use awk
Awk tutorial: awk regex example
Awk tutorial: awk loop example: awk for and while
awk if else, if else if else and awk if else nested example
Awk tutorial: awk NR FNR difference
Awk tutorial: awk sort uniq
Awk tutorial: split on character awk or cut
Awk tutorial: awk newline character
Awk tutorial: three ways of awk execution
How to print tree directory structure in linux/unix
Linux shell batch move files, delete spaces, rename files

Add a Comment

Your email address will not be published. Required fields are marked *