如何使用cygwin排序对第n列上的制表符分隔文件进行排序? [英] How do I sort a tab separated file on the nth column using cygwin sort?
问题描述
我有一个巨大的标签分隔文件,我想在其第2列排序。我需要使用tab字符作为cygwin排序中的字段分隔符。所以我需要这样的:
I have a huge tab separated file which I want to sort on its 2nd column. I need to use the tab character as the field delimiter in cygwin sort. So I need something like this:
sort -t \t -k 2,2 in.txt > out.txt
但是命令提示符按字面计算'\t',而不是制表符。注意,我需要在运行Cygwin的Windows机器上执行此操作。变化形式,例如
But the command prompt evaluates '\t' literally and not as the tab character. Note that I need to do this on a Windows machine running Cygwin. Variations such as
sort -t "\t"
sort -t \"\t\"
不工作,也不会将此放入具有实际标签的cmd文件中
don't work, neither does putting this in a cmd file with an actual tab in place of the \t above.
编辑:使用DOS shell或Cygwin bash shell的解决方案很好。
A solution using either the DOS shell or the Cygwin bash shell is fine.
推荐答案
在我的机器上(Mac bash提示符,GNU排序...)这样工作:
On my machine (Mac bash prompt, GNU sort ...) this works:
sort -t ' ' -k 2,2 in.txt > out.txt
(引号之间的真实选项卡。)
(A "real" tab between the quotes.)
要获得标签,我输入CTRL-V,TAB(CTRL-V,后跟TAB)。
To get the tab there I type CTRL-V, TAB (CTRL-V followed by TAB).
测试它在Windows机器上的cygwin提示符,它的工作原理相同(如我所料,bash是bash)。
I've now tested it on a Windows machine from the cygwin prompt and it works the same there (as I expected, bash is bash).
这篇关于如何使用cygwin排序对第n列上的制表符分隔文件进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!