【问题标题】:How display one line and sort a file in unix shell?如何在 unix shell 中显示一行并对文件进行排序?
【发布时间】:2013-07-09 14:08:14
【问题描述】:

我有这种文件:

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   

我该怎么做?

【问题讨论】:

    标签: unix sorting row ksh


    【解决方案1】:
    # 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 默认加入制表符

    【讨论】:

    • 它不起作用。此说明在 if 条件内,即在 while cicle 内。可能有问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 2021-12-17
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多