heszek
heszek

Reputation: 37

Counting the same lines from output

I want to list all shells with number of how many users have this shell set as default to get example output like this :

 13 /bin/bash
  6 /sbin/nologin
  1 /usr/sbin/nologin

the only command that I was managed to create is like this:

cut -d: -f1,7 /etc/passwd | grep -c bash

which returns me only the number of users with set bash as default

Can anyone tell me how should I modify this to get output as I mentioned before?

Upvotes: 0

Views: 76

Answers (1)

glenn jackman
glenn jackman

Reputation: 247162

First, you only want column 7 from the passwd file. The usernames will just get in the way. Then sort and use the uniq command to count them:

$ cut -d: -f7 /etc/passwd | sort | uniq -c
      2 /bin/bash
     24 /bin/false
      1 /bin/sync
      1 /usr/local/bin/fish
     16 /usr/sbin/nologin

Upvotes: 1

Related Questions