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}'


Add a Comment

Your email address will not be published.