Count Unique Rows

Create Example File With List Of Names

Notice that we have duplicated rows

echo 'Luca Gartside' >> adventurers.txt
echo 'Reule Smyth' >> adventurers.txt
echo 'Spencer Smit' >> adventurers.txt
echo 'Spencer Smit' >> adventurers.txt
echo 'Spencer Smit' >> adventurers.txt
echo 'Uli Pinetotem' >> adventurers.txt
echo 'Uli Pinetotem' >> adventurers.txt
echo 'Uli Pinetotem' >> adventurers.txt

View File

cat adventurers.txt
Luca Gartside
Reule Smyth
Spencer Smit
Spencer Smit
Spencer Smit
Uli Pinetotem
Uli Pinetotem
Uli Pinetotem

Get Unique Rows

cat adventurers.txt | uniq
Luca Gartside
Reule Smyth
Spencer Smit
Uli Pinetotem

Get Duplicated Rows

cat adventurers.txt | uniq -d
Spencer Smit
Uli Pinetotem

Count Unique Rows

uniq filters out all non-unique rows. wc -l counts the number of lines.

cat adventurers.txt | uniq | wc -l
4