排序制表符分隔的文件基于列排序的bash命令 [英] Sort a tab delimited file based on column sort command bash

查看:103
本文介绍了排序制表符分隔的文件基于列排序的bash命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图梳理基础上,第四列此文件。我想要的文件的基础上,第四列的值重新排序。

I am trying to sort this file based on the fourth column. I want the file to reordered based on the values of the fourth column.

文件:

2   1:103496792:A   0   103496792
3   1:103544434:A   0   103544434
4   1:103548497:A   0   103548497
1   1:10363487:T    0   10363487

我想它排序是这样的:

I want it sorted like this:

1   1:10363487:T    0   10363487
2   1:103496792:A   0   103496792
3   1:103544434:A   0   103544434
4   1:103548497:A   0   103548497

我试过这个命令:

I tried this command:

sort -t$'\t' -k1,1 -k2,2 -k3,3 -k 4,4 <filename>

但我得到的非法变量名错误。有人可以帮我?

But I get illegal variable name error. Can somebody help me with this?

推荐答案

要排序的第四列中只使用了 -k 4,4 选择。

To sort on the fourth column use just the -k 4,4 selector.

sort -t $'\t' -k 4,4 <filename>

您可能还需要 -V 这更自然排序号。例如,产生 1 2 10 ,而不是 1 10 2 (字典顺序)。

You might also want -V which sorts numbers more naturally. For example, yielding 1 2 10 rather than 1 10 2 (lexicographic order).

sort -t $'\t' -k 4,4 -V <filename>

如果你得到关于 $'\\ t'的错误然后确保你的shell是bash。也许你错过了#!/斌/庆典在你的脚本的顶部?

If you're getting errors about the $'\t' then make sure your shell is bash. Perhaps you're missing #!/bin/bash at the top of your script?

这篇关于排序制表符分隔的文件基于列排序的bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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