我试过 sort -n test.text > test.txt
。但是,这给我留下了一个空文本文件。这是怎么回事,我该怎么做才能解决这个问题?
最佳答案
排序不会就地排序文件。它输出一个排序的副本。
你需要 sort -n -k 4 out.txt > sorted-out.txt
。
编辑:要获得您想要的顺序,您必须使用倒序读取的数字对文件进行排序。这样做:
cut -d' ' -f4 out.txt | rev | paste - out.txt | sort -k1 -n | cut -f2- > sorted-out.txt
更多学习-
sort -nk4 file
-n for numerical sort
-k for providing key
or add -r option for reverse sorting
sort -nrk4 file
关于linux - 如何对文本文件进行数字排序,然后将结果存储在同一个文本文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29829787/