如何使用Linux命令Sort按第4列(数字顺序)对文本文件进行排序? [英] how to use Linux command Sort to sort the text file according to 4th column, numeric order?

查看:117
本文介绍了如何使用Linux命令Sort按第4列(数字顺序)对文本文件进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的文件(用空格分隔):

I have a file like this(which is space delimited):

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

,我想使用 sort 命令根据第4列对文件进行排序.我在互联网上到处都可以找到它,而且我发现修女可以用的不同解决方案!!我什至在stackoverflow中发现了类似的问题,但该答案对我没有用!所以这些是我正在使用的命令,无法正常工作!

and I want to use sort command to sort the file according to 4th column. I looked it up everywhere on internet and I find different solutions which nun works!! I even find similar question in stackoverflow which the answer didn't work for me! so these are the commands that I'm using and are not working!

sort -n -k 4,1 out1.txt
sort -n -k 4 out1.txt
sort -n -k4 out1.txt
sort -nk4 out1.txt
sort +4 out1.txt

因此,在运行所有这些命令之后,我得到以下输出(与我的输入相同):

so after running all these commands I get this output( which is identical to my input):

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

我想要这样的输出:

AX-19 Chr1_419087 1 41908741 T C 0 15 0.067
AX-20 Chr1_419087 1 41908740 T C 0 13 0.067
AX-18 Chr1_419085 1 41908545 T C -1 98 0.51

推荐答案

sort -nk4 file

-n for numerical sort
-k for providing key

或添加 -r选项进行反向排序

sort -nrk4 file

这篇关于如何使用Linux命令Sort按第4列(数字顺序)对文本文件进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆