Raveen Kumar

AWK

Example 1

awk -F ',' '{print $NF}' {{filename}}

To print only rows with columns matching a specific string

awk '$3 == "hello"' file

This will match with, 1 2 hello something but not with, 1 2 world something

Example 2: Awking and cutting some stuff

Lets assume that you want to print the 1st and 3rd field in one line.

echo "A:B:C:D:E:F:G" | awk -F ':' 'ORS=" " {print $1} {print $3}'

Here ORS stands for, The output record separator, by default its a newline.

Now lets see how to use cut to print the same,

echo "A:B:C:D:E:F:G" | cut -d ":" -f 1,3 --output-delimiter=" "

Now lets print everything except 1st and 3rd field,

echo "A:B:C:D:E:F:G" | cut -d ":" -f 1,3 --output-delimiter=" " --complement

And that’s all folks.

Books and reading materials

#Awk #Linux #Command-Line