Av1541
Av1541

Reputation: 57

How to sort a numbered text file in unix?

Ex: I have a text file

1.dog
2.cat
3.apple
4.bear

And I want to sort it to

3.apple
4.bear
2.cat
1.dog

I don't understand how to sort it because there is no space after the period and the first letter of the lines so I'm not able to simply say sort +1 file.txt or anything. Is there any way I can use some sort of substring to dodge the numbered list and period to sort it based on what comes afterwards?

Upvotes: 0

Views: 29

Answers (1)

Gilles Quénot
Gilles Quénot

Reputation: 185161

Try this :

sort -t . -k2 file

Check man sort

Upvotes: 1

Related Questions