如何删除复杂的重复列

时间:2013-09-11 06:37:13

标签: unix

  Date              ID     S_count U_count
09/01/13 12:00 AM    23    30      0
09/01/13 12:00 AM    27    2       0
09/01/13 12:00 AM    27    4992    0
09/01/13 12:00 AM    8     1036    0
09/01/13 12:00 AM    8     5600    0
09/01/13 01:00 AM    23    37      0
09/01/13 01:00 AM    27    1       0
09/01/13 01:00 AM    27    4905    0
09/01/13 01:00 AM    8     1230    0
09/01/13 12:00 AM    27    0       2
09/01/13 12:00 AM    8     0       1036
09/01/13 01:00 AM    27    0       1
09/01/13 01:00 AM    8     0       1230
09/01/13 02:00 AM    27    0       1
09/01/13 02:00 AM    8     0       1477
09/01/13 01:00 AM    8     5401    0

输出将如下:

Date                 ID    S_count U_count
09/01/13 12:00 AM    23    30      0
09/01/13 12:00 AM    27    2       0
09/01/13 12:00 AM    27    4992    0
09/01/13 12:00 AM    8    1036     0
09/01/13 12:00 AM    8    5600     0
09/01/13 01:00 AM    23    37      0
09/01/13 01:00 AM    27    1       0
09/01/13 01:00 AM    27    4905    0
09/01/13 01:00 AM    8    1230     0
09/01/13 01:00 AM    8    5401     0

还有更多这样的记录..我想删除那些重复的行。 S_count值与U_count值类似。所以需要删除U_count行。 注意:S_count和U_count的时间和ID都相同。

2 个答案:

答案 0 :(得分:1)

使用awk

$ awk 'NR==1 || ($6==0)' inputfile
  Date              ID     S_count U_count
09/01/13 12:00 AM    23    30      0
09/01/13 12:00 AM    27    2       0
09/01/13 12:00 AM    27    4992    0
09/01/13 12:00 AM    8     1036    0
09/01/13 12:00 AM    8     5600    0
09/01/13 01:00 AM    23    37      0
09/01/13 01:00 AM    27    1       0
09/01/13 01:00 AM    27    4905    0
09/01/13 01:00 AM    8     1230    0
09/01/13 01:00 AM    8     5401    0

答案 1 :(得分:0)

使用awk的另一种简单方法

awk -F " " '$5>0' temp.txt

<强>输出:

09/01/13 12:00 AM    23    30      0
09/01/13 12:00 AM    27    2       0
09/01/13 12:00 AM    27    4992    0
09/01/13 12:00 AM    8     1036    0
09/01/13 12:00 AM    8     5600    0
09/01/13 01:00 AM    23    37      0
09/01/13 01:00 AM    27    1       0
09/01/13 01:00 AM    27    4905    0
09/01/13 01:00 AM    8     1230    0
09/01/13 01:00 AM    8     5401    0