Reputation: 22725
How do I lookup username using first and last name?
Something which does the reverse of getent passwd <username>
finger
is taking forever and doesn't display exact match. i.e it displays all logins with same first name or same last name
Upvotes: 0
Views: 189
Reputation: 10271
For passwd entries like
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false
You'd extract the 5th :
-delimited field, extract the first ,
-delimited field of that, and check if that equals the first name followed by a blank followed by the last name.
firstname=PulseAudio
lastname=daemon
getent passwd | awk -F: -vfirst="$firstname" -vlast="$lastname" '{
split($5,name,",");
if(name[1]==(first " " last)) {
print $1;
}
}'
If you want the check to be case-insensitive, you can add calls to tolower()
on each side of the comparison.
Upvotes: 1