I have a file that looks like this:
2836344588 ... ... N fs1q
2836344589 ... ... N fp2q
2836374222 ... ... N fp3q
2836374223 ... ... N fp6q
2836374224 ... ... N fp7q
2836384836 ... ... N fs2q
2836384837 ... ... N fp1q
2836384838 ... ... N fp4q
2836384839 ... ... N fp5q
2836384957 ... ... N fs3q
2836384958 ... ... N fs7q
2836404416 ... ... N fs5q
2836414186 ... ... N fs6q
2836434267 ... ... N fs4q
I would like to sort it by the second and the third characters of the fifth column: sorting on the second character should be done in reverse alphabetic order (s
should come before p
) and sorting on the third character should be done in a regular (i.e. non-reversed) numeric order.
I thought I could achieve this with:
sort -k5.2r -k5.3n
but this results in:
2836384958 ... ... N fs7q
2836414186 ... ... N fs6q
2836404416 ... ... N fs5q
2836434267 ... ... N fs4q
2836384957 ... ... N fs3q
2836384836 ... ... N fs2q
2836344588 ... ... N fs1q
2836374224 ... ... N fp7q
2836374223 ... ... N fp6q
2836384839 ... ... N fp5q
2836384838 ... ... N fp4q
2836374222 ... ... N fp3q
2836344589 ... ... N fp2q
2836384837 ... ... N fp1q
where sorting on the third character of the fifth column is also reversed.
How can I sort this file so that that reverse sorting happens only on the second character (all 's' lines come before all the 'p' lines) but not on the third character? In other words, how do I get to this desired output:
2836344588 ... ... N fs1q
2836384836 ... ... N fs2q
2836384957 ... ... N fs3q
2836434267 ... ... N fs4q
2836404416 ... ... N fs5q
2836414186 ... ... N fs6q
2836384958 ... ... N fs7q
2836384837 ... ... N fp1q
2836344589 ... ... N fp2q
2836374222 ... ... N fp3q
2836384838 ... ... N fp4q
2836384839 ... ... N fp5q
2836374223 ... ... N fp6q
2836374224 ... ... N fp7q
Many thanks in advance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…