如何在unix shell中显示一行并对文件进行排序?

时间:2013-07-09 14:08:15

标签: unix sorting row ksh

我有这样的档案:

TAB  |  STAT |  RECORDS
------------------------
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26
TAB1
DUPKEY
26

正如您所看到的,有多条线,它们是相同的。我需要的是创建一个名为report.dat的文件,输出将是

TAB  |  STAT |  RECORDS
------------------------
TAB1   DUPKEY     26   

我该怎么做?

1 个答案:

答案 0 :(得分:0)

# print the first 2 lines
sed 2q file
# skip the first 2 lines, join 3 lines into 1, then get unique lines
sed 1,2d file | paste - - - | sort -u
TAB  |  STAT |  RECORDS
------------------------
TAB1    DUPKEY  26

paste默认情况下与制表符加入