tags:

views:

165

answers:

3

Given following command:

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

why does awk output:

1: 
+5  A: 

"-F" is a command line argument not awk syntax, try:

 echo "1: " | awk -F  ":" '/1/ {print $1}'
Jürgen Hötzel
+4  A: 

-F is an argument to awk itself:

$echo "1: " | awk -F":" '/1/ {print $1}'
1
danben
+6  A: 

If you want to do it programatically, you can use the FS variable:

echo "1: " | awk 'BEGIN { FS=":" } /1/ { print $1 }'

Note that if you change it in the main loop rather than the BEGIN loop, it takes affect for the next line read in, since the current line has already been split.

Dennis Williamson