For example, this is the list.txt
Joe 3
Jack 1
Ulysses 6
Fox 2
Cassidy 1
Jones 6
Kevin 7
Then the output should be 5
because there are 5 different values in the 2rd column.
How should I finish this by only using sort
cut
wc
uniq
?
I have an idea, first use sort -k2n
to sort the second column in increasing order and then use uniq
to eliminate the second-column duplicated rows, and then the result would be like
Cassidy 1
Fox 2
Joe 3
Jones 6
Kevin 7
and then I use cut -d ' ' -f2
to list all the numbers like 1 2 3 6 7
and then I use wc -d
to count the number of distinct values and this will return 5
.
What should I do in the uniq
part to eliminate the duplicated rows with the same number?
Is there a simple way to accomplish this?