Village
Village

Reputation: 24363

How to alphabetize all of the rows in a CSV file, column by column?

I have a three-column CSV file, like this:

chips@food@f
pizza@food@f
tiger@animal@a
fish@animal@a
marshmallow@food@f
New Years@festivals@f

I need to alphabetize the rows, first by column 3, then column 2, then column 1. The output would be:

fish@animal@a
tiger@animal@a
New Years@festivals@f
chips@food@f
marshmallow@food@f
pizza@food@f

How can I sort the data in this manner?

Upvotes: 1

Views: 288

Answers (1)

kev
kev

Reputation: 161664

You can try sort command:

$ sort -t@ -k3,3 -k2,2 -k1,1 input.csv
fish@animal@a
tiger@animal@a
New Years@festivals@f
chips@food@f
marshmallow@food@f
pizza@food@f

Upvotes: 7

Related Questions