UNIX整理,与原发性和继发键 [英] unix sorting, with primary and secondary keys

查看:99
本文介绍了UNIX整理,与原发性和继发键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个文件的更多字段进行排序。
样本制表符分隔的文件是:

I would like to sort a file on more fields. A sample tab separated file is:

a   1   1.0
b   2   0.1
c   3   0.3
a   4   0.001
c   5   0.5
a   6   0.01
b   7   0.01
a   8   0.35
b   9   2.3
c   10  0.1
c   11  1.0
b   12  3.1
a   13  2.1

,我想将它按字母顺序排序由1场(与 -d ),当FIELD1是一样的,排序场3(与 -g 选项)。

And i would like to have it sorted alphabetically by field 1 (with -d), and when field1 is the same, sort by field 3 (with the -g option).

一个没有完成此类工作。我attemps是(与真正的TAB字符,而不是<标签>

A didn't succeed in doing this. My attemps were (with a real TAB character instead of <TAB>):

cat tst | sort -t"<TAB>" -k1 -k3n
cat tst | sort -t"<TAB>" -k1d -k3n
cat tst | sort -t"<TAB>" -k3n -k1d

这些都不是工作。我不知道,如果是那种即使能够做到这一点。我会写一个解决方法脚本,所以我只是好奇是否只有用一个解决方案的排序

推荐答案

借助手动显示了一些例子。

The manual shows some examples.

在按照zseder的评论,这个作品:

In accordance with zseder's comment, this works:

sort -t"<TAB>" -k1,1d -k3,3g

标签理论上应该也是这样工作排序-t\\ t的

如果没有上述工作由标签界定,这是一个丑陋的解决方法:

If none of the above work to delimit by tab, this is an ugly workaround:

TAB=`echo -e "\t"`
sort -t"$TAB"

这篇关于UNIX整理,与原发性和继发键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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