Can I use a field separator consisting of multiple characters? Like I want to separate words which contain quotes and commas between them viz.
\"School\",\"College\"
Yes, you can use multiple characters for the -F
argument because that value can be a regular expression. For example you can do things like:
echo "hello:::my:::friend" | gawk -F':::' '{print $3}'
which will return friend
.
The support for regexp as the argument to -F
is true for nawk
and gawk
(GNU awk), the original awk
does not support it. On Solaris this distinction is important, on Linux it is not important because awk
is effectively a link to gawk
. I would therefore say it is best practice to invoke awk as gawk
because then it will work across platforms.