Sort and Unique in Shell

Level 241 keystrokes

Counts how many times each name appears in names.txt and lists the most frequent names first.

Shell code

# sort groups identical names, because uniq only merges adjacent duplicates
# uniq -c prefixes each name with its count; sort -rn puts the largest count first
1cat names.txt | sort | uniq -c | sort -rn

Output

      5 Alice
      3 Bob
      2 Carol
      1 Dan
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • |× 3
  • -× 2
  • .× 1

More Shell examples at level 2

← Shell typing practice