Shell-script - Parse passwd file and get ser input, Scripting to parse user input
Parse passwd file and get ser input
shell script to parse /etc/passwd file and place it as inputHow to find a user is present or not
# grep -i 'avahi' /etc/passwd avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
The above command will grep for the user avahi and will grep the lines present in the server or /etc/passd file.
Cut command to parse the file and make it as a input
# grep -i 'avahi' /etc/passwd | cut -d: -f 1,3,5,6 avahi-autoipd:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd avahi:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon
The above command will cut the username, User-id or UID, User Comment and the users home directory
Translate the required field to into columns
# grep -i 'avahi' /etc/passwd | cut -d: -f 1,3,5,6 | tr ':' '\t' avahi-autoipd 170 Avahi IPv4LL Stack /var/lib/avahi-autoipd avahi 70 Avahi mDNS/DNS-SD Stack /var/run/avahi-daemon
The above command will translate the ":" into tab separated column. which will easy to use as user input using awk command.
The topic on Shell-script - Parse passwd file and get ser input is posted by - Linux Guru
Hope you have enjoyed, Shell-script - Parse passwd file and get ser inputThanks for your time