How do you sort a file by the last number in a line?
Assuming the last character of every line is a number. INPUT:
facebook.com/pageA,2,11,11
facebook.com/pageB,0,0,20
facebook.com/pageC,0,0,6
facebook.com/pageD,1,22,239
Desired Output:
facebook.com/pageC,0,0,6
facebook.com/pageA,2,11,11
facebook.com/pageB,0,0,20
facebook.com/pageD,1,22,239
Help??
You can use sort
.
sort -n -t, -k4 INPUT
If your input file has different columns in each line then you can make the last column as first column, sort by it and then remove it.
awk '{print($NF,$0)}' FS=, OFS=, inputFile | sort -t, -nk1 | cut -f2- -d,
Use rev
to reverse each line, then sort, then re-reverse:
rev < $file | sort | rev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With