0

My data looks as follows:

1 3 4 2016 2 bam
2 0 0 1998 2 bbm
3 0 0 1900 2 bcm
4 3 0 2000 1 bdm

I would like it to be as follows:

1 0 0 1900 2 bcm
2 0 0 1998 2 bbm
3 3 0 2000 1 bdm
4 3 4 2016 2 bam

I tried sort -n -k4 it doesn't give me what I want, is there any other command I can use?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Jubi
  • 3
  • 3

1 Answers1

1

It looks like columns 1 and 4 in your output are sorted independently. It can't be done with sort that way. But if you are interested in sorting by 4th column specify field separator with -t

sort -k4,4n -t ' '

In case you want to additionally sort by other columns e.g. numerically by 4th, then alphabetically by 5th and then numerically by 1st just add them with -k

sort -k4,4n -k5,5 -k1,1n -t ' '
Marcin
  • 444
  • 3
  • 14
  • Thank you, I was not very clear about my first column, it is number 1-n and i want the line of the earliest birth year to appear as my number 1 – Jubi Feb 09 '17 at 09:51