Using Linux cut, sort and uniq

I have a list with population, year and county, and I need to cut out the list and then find the number of uniq counties.

The list starts as follows:

#Population,    Year,   County
3900,   1969,   Beaver
3798,   1970,   Beaver
3830,   1971,   Beaver
3864,   1972,   Beaver
3993,   1973,   Beaver
3976,   1974,   Beaver
4064,   1975,   Beaver

This list has many more, and many more counties. I need to cut out the county column, sort it, and then output the number of uniq counties. I tried this command:

 cut -c3- list.txt | sort -k3 | uniq -c

But this does not shorten the third list or sort it alphabetically. What am I doing wrong?

+3
source share
2 answers

You can add a separator, which is a comma in your case:

cut -f 3 -d, list.txt | sort | uniq

then -cindicates the position of the symbol, not the field that is indicated by -f.

, , . awk '{print $1}',

cut -f 3 -d, list.txt | awk '{print $1}' | sort | uniq

[]

Aaaaand. cut 3- , , , . 1 , uniq.

+8

awk ( ), sort/uniq.

awk '{print $3}' list.txt |sort |uniq -c
+3

All Articles