Use AWK to print column’s from file

In many times, we all may required an output of specific column in a file, for example we want to know the users in the system, for this we need to open passwd file in /etc folder and view, but the file is having so much of information, it is time consuming  to takeout user name, in that case we use the power of awk to the output we desired, check out how

more /etc/passwd | awk -F:  ‘{print $1}’

This will print only the user name from /etc/passwd file.

command description

more –  command to view files page by page ( we can also use less, cat etc ….)

/etc/passwd – The file you want take the information from

awk – power tool

-F : – This uses “:” as field separator, default separator is space/tab, we are changing the behavior using -F option

‘{print $1}’ – This will print the first column of the file. ( we can use any field we want )

another example to print user name and full name of the user

more /etc/passwd | awk -F: ‘{print $1, $5}’

About Anoop Nair

I am a Linux and Networking geek, Interest to learn more and fun to do new experiments, happy to share knowledge that I have learned and experienced in my life and carrier, also trying to learn more on Firewalls, Linux, Switching, Routing etc..............

Check Also

MySql replication

Disaster recovery of Mysql using DRBD and Heartbeat

Disaster recovery (DR) is the process, policies and procedures that are related to preparing for …