How can I use ":" as an AWK field separator?

user173446 picture user173446 · Apr 9, 2010 · Viewed 569k times · Source

Given the following command,

echo "1: " | awk '/1/ -F ":" {print $1}'

why does AWK output:

1:

?

Answer

Jürgen Hötzel picture Jürgen Hötzel · Apr 9, 2010

"-F" is a command line argument, not AWK syntax. Try:

 echo "1: " | awk -F  ":" '/1/ {print $1}'