how to use Linux command Sort to sort the text file according to 4th column, numeric order?
sort -nk4 file
-n for numerical sort
-k for providing key
or add -r option
for reverse sorting
sort -nrk4 file
sort
does not sort the file in-place. It outputs a sorted copy instead.
You need sort -n -k 4 out.txt > sorted-out.txt
.
Edit: To get the order you want you have to sort the file with the numbers read in reverse. This does it:
cut -d' ' -f4 out.txt | rev | paste - out.txt | sort -k1 -n | cut -f2- > sorted-out.txt
It should be
sort -k 4n out1.txt
Just tested this with GNU sort (--debug enabled):
$ tac input | /bin/sort --debug -k 4n
/bin/sort: using simple byte comparison
/bin/sort: key 1 is numeric and spans multiple fields
AX-18 Chr1_419085 1 41908545 T C -1 98 0.51
________
___________________________________________
AX-19 Chr1_419087 1 41908740 T C 0 15 0.067
________
___________________________________________
AX-20 Chr1_419087 1 41908741 T C 0 13 0.067
________
___________________________________________