Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
using Linux cut, sort and uniq

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

The list starts off like this:

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

There is much more to this list, and many more counties. I have 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 cut the third list, nor does it sort it alphabetically. What am I doing wrong?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

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

then, -c specifies character position, rather than field, which is specified with -f.

To strip spaces in front you can pipe this all through, e.g. awk '{print $1}', i.e.

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

[edit]

Aaaaand. If you try to cut the 3rd field out, you are left with only one field after the pipe, so sorting on the 3rd field won't work, which is why I omitted it in my example. You get 1 field, you just sort on it and the apply uniq.

over 4 years ago · Santiago Trujillo Report

0

You can use awk to extract third field (space delimited), and then do your sort/uniq stuff.

awk '{print $3}' list.txt |sort |uniq -c
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!