Re : grep command.
I have to search a file for the names of all the students in the school's Linux system. I am able to do this and return about 665 names. (First string of /etc/passwd
file).
From there, I need to sort on the students who's name ends in 'o' and also those who have two or more 'o' in their name.
This isn't actually for me — it is indeed homework but for a friend.
I am way past the age of homework :)
He has to use grep to get the results.
I haven't used grep for years, I played a round a little but can't stay away from using other commands to achieve this. I was just curious to see if someone in the community knew how to do this using grep.
For the names in the /etc/passwd
file ending in letter 'o' :
grep -Eo '^[a-zA-Z0-9._-]+' /etc/passwd | grep -Eo 'o$'
This works but doesn't display the whole name , just the letter 'o' for the one single match to the request in the file.
Not sure :
1) how to display the output , ie.. whole name ? 2) how to search for those names with more than one 'o' in their name ?
From the /etc/passwd
file for example....
I want to display the output of all users ending in the letter 'o' in a file
I want to display all users that contain more than one letter 'o' in another file