Print first column of passwd

The delimiter used to differentiate different fields in the /etc/passwd files is colon ' : ' . Therefore we need to look only after the semicolon.
To deal with column based files or formatted text the most commonly used command is awk.
Command below will print out the first column of /etc/passwd file:

 awk < /etc/passwd -F: '{ print $1 }'

Here

awk             is the text processor

< /etc/passwd    will serve as input file for awk

-F:             is a parameter for awk that specifies the delimiter. In our      
                           case is colon.

{ print $1 }    This will print the first line. You can put $2, $3 etc. to
                           print respective column.

My command produced following output:

 root  
 daemon  
 bin  
 sys  
 adm  
 lp  
 uucp  
 nuucp  
 smmsp  
 listen  
 gdm  
 webservd  
 postgres  
 svctag  
 nobody  
 noaccess  
 nobody4  

Comments

Popular Posts