No need to explicitly set FS! Just use:
echo test,123 | awk -F, '{print $1}'
echo test,123 | awk -F, '{print $1}'
awk 'BEGIN {FS=":"};{print $1}'
One benefit of the FS variable over -F, at least in original awk, is that by using FS the delimiter can be more than one character. I guess that's why I remember FS before I remember -F. More flexible. $ echo 'Sample123string42with777numbers' | awk -F'[0-9]+' '{print $2}'
string awk -v FS="\t"EXAMPLES Print and sort the login names of all users:
BEGIN { FS = ":" }
{ print $1 | "sort" }
The above is from the GAWK manpage. FWIW, the first example under EXAMPLES uses FS not -F.There is nothing wrong with using FS instead of -F.
FS is not used on the command line and doing so is asking for trouble. FS is a built-in variable and as such is treated specially.
cat > 1.awk << eof
{ print $ARGC }
eof
echo|nawk -f 1.awk FS=":"
echo|gawk -f 1.awk FS=":"
echo|nawk -f 1.awk -v FS=":"
echo|gawk -f 1.awk -v FS=":" echo "" | awk '{print Bla;}' Bla="Hello."