简体   繁体   中英

How to sort content of a text file in Terminal Linux by splitting at a specific char?

I have an assignment in school to sort a files content in a specific order. I had to do it with Windows batch-files first and now I have to do the same in Linux. The file looks more or less like this the whole way through:

John Doe : Crocodiles : 1035

In windows I solved the problem by this:

sort /r /+39 file.txt

The rows in the file are supposed to get sorted by the number of points (which is the number to the right) in decreasing order. Also the second part of the assignment is to sort the rows by the center column.

How can I get the same result(s) in Linux? I have tried a couple of different variations of the sort command in Linux too but so far without success.

I'd do it with:

sort -nr -t: -k3

-nr - numbers reverse order -t: - key separator colon -k3 - third field

Windows命令sort /r /+39 file的Linux等效项是:

sort -r -k +39 file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM