How to print /etc/passwd in different output?

eawedat

New Member
Joined
Feb 6, 2023
Messages
5
Reaction score
2
Credits
51
i would like to write a script that prints /etc/passwd as this output:

root daemon bin sys …
x x x x
0 1 1 2
root daemon bin sys

first line has all user accounts in same row
second line has all encrypted passwords (x) in same row
third line has all user ids in same row
and etc…
 


Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,181
Reaction score
2,172
Credits
3,302
This sounds like it's something for school lol.

Code:
awk -F: '{users = users $1 " "; passwords = passwords $2 " ";
         uids = uids $3 " "; gids = gids $4 " ";
         gecos = gecos $5 " "; homedirs = homedirs $6 " ";
         shells = shells $7 " "} 
         END {print users; print passwords; print uids;
              print gids; print gecos; print homedirs; 
              print shells}' /etc/passwd

Edit: You'll likely get in trouble w/ your teacher if you can't explain how you figured that out haha
 
OP
E

eawedat

New Member
Joined
Feb 6, 2023
Messages
5
Reaction score
2
Credits
51
This sounds like it's something for school lol.

Code:
awk -F: '{users = users $1 " "; passwords = passwords $2 " ";
         uids = uids $3 " "; gids = gids $4 " ";
         gecos = gecos $5 " "; homedirs = homedirs $6 " ";
         shells = shells $7 " "}
         END {print users; print passwords; print uids;
              print gids; print gecos; print homedirs;
              print shells}' /etc/passwd

Edit: You'll likely get in trouble w/ your teacher if you can't explain how you figured that out haha
Thank you Rob, i will give you the credit ))
actually, i thought about some for or while loops to do the job, or using cut
 


Latest posts

Top