Awk one of the most powerful command for text preprocessing that makes work easy.Awk can be used almost everywhere in system monitoring scripts, where efficiency is key.This is the most important command.This is the command that all core linux users should be know.
Let have few example to show power of Awk:
starting with simple commands
Lets us take the input as the /etc/passwd file
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
Task: To trip out only the user names from the password file(first field)
awk -F: ‘{print $1}’ /etc/passwd
-F should be followed by the delimiter here the Delimiter is ‘:’ and $1 is the first field which is required.
The output is:
daemon
bin
sys
sync
games
man