0

I have managed to get the total number of users on the system with this:

$ getent passwd | wc -l

I need the number of users on the system with a certain first name (for example 'Josh') and whose usernames start with a 'b'. How? I don't know the syntax for this.

4
  • Are you use all users have proper stanza as user name? Sep 24, 2021 at 9:09
  • 1
    What did you try so far?
    – pLumo
    Sep 24, 2021 at 9:11
  • I tried searching the Internet for the syntax, but couldn't figure it out. I don't know what a stanza is. Sep 24, 2021 at 9:13
  • The stanza = comment for user, 5 field in the lines you get Sep 24, 2021 at 9:14

1 Answer 1

2

You can try something like:

getent passwd|awk -F: '$5 ~ /^Josh([ ,.]|$)/ && $1 ~ /^b/'|wc -l
2
  • @pLumo, unfortunately this will include also Joshua, which is not the OP intention Sep 24, 2021 at 9:28
  • 1
    @StéphaneChazelas, thank you for the suggestion, will "steal" it :) Sep 24, 2021 at 9:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .