I want to read the users from /etc/passwd file.My /etc/passwd file is
/etc/passwd
root:eRYFFjZ2./oo:0:0:root:/:/bin/bash
nobody:*:99:99:Nobody:/:
ftp:*:14:50:FTP User:/:/bin/false
#guest
guest:/QP8Q2QieMWi4:500:500:Guest:/:/bin/bash
gst1:x:1002:1003:,,,:/home/gst1:/bin/bash
#gend
#admin
ad1:x:1003:1004:,,,:/home/adm1:/bin/bash
ad2:x:1004:1005:,,,:/home/adm2:/bin/bash
#adend
I want to get users from this file using a script.first read guest and gst1 .Then ad1,ad2. i tried to use
awk'#guest/{flag-1;next}/#gend/{flag=0}flag' /etc/passwd
awk'#admin/{flag-1;next}/#adend/{flag=0}flag' /etc/passwd
this gives me two lines
guest:/QP8Q2QieMWi4:500:500:Guest:/:/bin/bash
gst1:x:1002:1003:,,,:/home/gst1:/bin/bash
ad1:x:1003:1004:,,,:/home/adm1:/bin/bash
ad2:x:1004:1005:,,,:/home/adm2:/bin/bash
I want to extract first 'guest' do some operation with it then extract 'gst1' . Then i want to extract admin users names(ad1 and ad2)
Is it possible to extract them one by one in a while loop.I want like this
start from label #guest
get user 'guest'
===do some work with 'guest'===
continue above steps for the users up to label #gend
I am running this linux in a embedded target and the file systems are custom built .