Home   Profile   Fun
#62 Linux  03.04.2007

The command awk


Print the first and third column of testfile1.
awk '{print $1,$3}' testfile

Filter all lines of testfile1 containing "whatever". Print the first and third column of these lines.
cat testfile1 | grep "whatever" | awk '{print $1,$3}'

It is also possible to control the output of the lines. In the examples before all lines are printed. Now we use a command that let us skip the first 3 lines. You can even chose a different separator to identify the columns. This is done with the -F option.
ls -lha | awk 'NR>3 {print $9}'