Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to display users of my linux whose name ends with a number

I want to display users in my linux whose name ends on number

I tried grep ‘[0-9]’ /etc/passwd but it displays all lines containing numbers

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use awk for this:

awk -F: '{ print $1}' /etc/passwd | grep '[0-9]$'

Alternatively you could also use cut

cut -d: -f1 /etc/passwd | grep '[0-9]$'

Both work essentially the same way. They split a line within the file using : as a delimiter and then print the first result of that split.

The grep command uses the end of string anchor $ to match the end of the user name.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading