Home > Software engineering >  File lines sorting according to index
File lines sorting according to index

Time:10-31

I have a file with the structure below. I want to order its lines by the second column defined by double points on bash, but I do not even know how to start. Would you be nice to help me order it?

input.txt

a:3:foo
b:1:bar
c:2:goo

output.txt

b:1:bar
c:2:goo
a:3:foo

CodePudding user response:

With sort

sort -nk2 -t: input.txt

Redirect the output to the new file.

sort -nk2 -t: input.txt > output.txt

See man sort

  •  Tags:  
  • bash
  • Related