Given following command:
echo "1: " | awk '/1/ -F ":" {print $1}'
why does awk output:
1:
Given following command:
echo "1: " | awk '/1/ -F ":" {print $1}'
why does awk output:
1:
"-F" is a command line argument not awk syntax, try:
echo "1: " | awk -F ":" '/1/ {print $1}'
-F
is an argument to awk
itself:
$echo "1: " | awk -F":" '/1/ {print $1}'
1
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.