Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

unix - Sort CSV file by column priority using the "sort" command

I have a csv file, and I would like to sort it by column priority, like "order by". For example:

3;1;2
1;3;2
1;2;3
2;3;1
2;1;3
3;2;1

If this situation was the result of a "select", the "order by" would be as follows: order by column2, column1, column3 - the result would be:

2;1;3
3;1;2
1;2;3
3;2;1
1;3;2
2;3;1

I'd like to know how to get this same result using "sort" command on Unix.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
sort --field-separator=';' --key=2,1,3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...