Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pull a line out of /etc/passwd if its corresponding shadow entry is 999999?

Tags:

I want to compare each user in the passwd file with his entry in the shadow file, and print out the whole line of the passwd file if the entry in the shadow file matches 999999. What is the easiest way in Perl to do this? Or I suppose I could awk the values out of one file and match in the other file? What is the best way of doing this?

like image 990
paul44 Avatar asked Feb 24 '10 13:02

paul44


1 Answers

awk -F":" 'FNR==NR&&$5=="99999"{user[$1];next}($1 in user)' /etc/shadow /etc/passwd

change FNR==NR&&$5=="99999" to FNR==NR&&$5=="99999"&&$2!="!!" if you want to exclude lines with "!!"

like image 149
ghostdog74 Avatar answered Oct 13 '22 08:10

ghostdog74