WeCodeAcademy

Sorting and Counting with sort and uniq

sort puts lines in order, and sort -r reverses it. uniq removes repeated neighbouring lines, so you almost always sort first. uniq -c also counts each line.

Examplebash
Open in editor »
/ $

Sort the counts to find the most common line.

Examplebash
Open in editor »
/ $
Quick check

Why do you usually run `sort` before `uniq`?

Your turn: write the code

names.txt is created for you with some repeated names. Print each name only once, in alphabetical order. (Checked on the output of your last command.)

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.