Awk and Bash: Print Linux/Unix User Accounts

There are ways how to do this:
awk -F':' '{ print $1 "\t"  $3 }' /etc/passwd
That would  print the username and the UID. You can also add the sort command at the end like
awk -F':' '{ print $1 "\t"  $3 }' /etc/passwd | sort
and this will sort alphabetically.

To add filter in the result, you can
awk -F':' '$1 == "hachiko" { print $1 "\t"  $3 }' /etc/passwd | sort
where hachiko is a username you wanted to print with its UID.

Hope this helps!

Comments

Popular posts from this blog

Using Oracle 11g thru VirtualBox appliance in Mac OS X Lion

Use Shell Editor for Eclipse for editing bash, ksh, csh in Unix/Linux system

LVM: How to remove a volume using pvremove