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}’