I have a file with following contents. I am looking to sort this file based on the last column (and third last but for another file) while retaining rest of the contents of the row.
ABC,DEF,GHI,-5,-8,-0.6,0.488
XYZ,JKL,MNO,3,-5,0.2,-0.342
STU,WXY,DEF,-1,4,0.01,0.345
If I use this command, it works as expected and shows the correct results:
awk '{print $NF,$0}' FILE | sort -nr | cut -f2- -d' '
XYZ,JKL,MNO,3,-5,0.2,-0.342
STU,WXY,DEF,-1,4,0.01,0.345
ABC,DEF,GHI,-5,-8,-0.6,0.488
But the same command on a bigger file gives an incorrect result. (The file I am looking to sort has 4M rows) Input:
ABC,DEF,GHI,-5,-8,-0.6,0.0488
XYZ,JKL,MNO,3,-5,0.2,-0.0342
STU,WXY,DEF,-1,4,0.01,0.0345
JKL,JKL,GHI,-2,-3,0.31,-0.0524
QRS,GHI,YUT,-3,-1,0.20,-0.0503
HUR,JTL,ZST,1,1,0.52,-0.0556
FTT,JL,MKI,0,2,0.21,-0.0529
FTC,JKL,ERW,-1,6,0.23,-0.0441
HJI,MHP,VGT,1,-6,0.80,-0.0433
BUT,IOP,HGT,2,2,0.2,-0.0439
XYZ,BGY,MNO,-2,1,0.01,-0.0416
But the same command on a bigger file gives an incorrect result.
- please tell us what that incorrect result is and create a minimal example that demonstrates that problem (if you don't know how else to do it, just do divide-and-conquer on your failing input to get to the minimal lines you need to reproduce it).