sipsorcery
sipsorcery

Reputation: 30714

Use shell utilities for equivalent of SQL group by on a CSV file

I've got a csv file where the left most column contains an ID field. Is there a clever way I can use any utility programs such as sed to find any ID's that are used more than once?

Upvotes: 2

Views: 199

Answers (1)

Michael Mior
Michael Mior

Reputation: 28752

If all you want is the IDs, then you can try

cut -d "," -f $NUM | sort -n | uniq -d

where $NUM is the number of the field containing the ID. The cut command will extract a list of ids, and the uniq command will show you only those which are duplicated.

Upvotes: 5

Related Questions