LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 989|回复: 4

求大侠帮忙(文本处理问题)

[复制链接]
发表于 2009-12-1 19:17:54 | 显示全部楼层 |阅读模式
各位大侠好:
      我有一个文本文件,和下面的一样,每1行分成3个部分,第一部分是时间,第二部分是报警代码,第三部分是报警内容,每一行的报警代码和报警内容一一对应。
2008-12-17 14:50        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:48        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:46        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:44        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:41        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:40        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:39        2006036        LD200-6036  Loader frame pusher forward error.
2008-12-17 14:30        2006036        LD200-6036  Loader frame pusher forward error.

2008-12-17 14:16        2006006        LD200-6006  Loader elevator up/down interlock.
2008-12-17 14:16        2006006        LD200-6006  Loader elevator up/down interlock.
2008-12-17 14:15        2006013        LD200-6013  Loader switch ON.
2008-12-17 14:12        2006013        LD200-6013  Loader switch ON.
2008-12-17 14:12        4006091        FEE00-6091  No work on 1st gripper
2008-12-17 14:10        13006001        AGR00-6001 Island position recognition error.
2008-12-17 14:07        13006001        AGR00-6001 Island position recognition error.
2008-12-17 13:52        13006001        AGR00-6001 Island position recognition error.

2008-12-17 12:37        9006055        ULD00-6055  Work request signal off error(back-end).
2008-12-17 12:32        9006055        ULD00-6055  Work request signal off error(back-end).
2008-12-17 12:16        6006002        PRF00-6002  Preform already done for work at preform position.
2008-12-17 12:12        13006001        AGR00-6001 Island position recognition error.
2008-12-17 11:00        4006001        FEE00-6001  Work align error
2008-12-17 09:56        31006065        WFT00-6065  Vacuum stage limit sensor wiring cut-off (open circuit).
2008-12-17 04:10        4006003        FEE00-6003  Work edge detection error
2008-12-17 04:10        4006227        FEE00-6227  Work drawing miss error
2008-12-17 04:09        4006003        FEE00-6003  Work edge detection error
2008-12-17 04:08        4006003        FEE00-6003  Work edge detection error
2008-12-17 04:07        4006003        FEE00-6003  Work edge detection error

2008-12-17 04:02        4006227        FEE00-6227  Work drawing miss error
2008-12-17 04:01        4006003        FEE00-6003  Work edge detection error
2008-12-17 04:00        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:59        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:59        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:58        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:56        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:54        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:54        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:53        4006003        FEE00-6003  Work edge detection error

2008-12-17 03:52        4006004        FEE00-6004  Work edge detection sensor ON
2008-12-17 03:52        4006003        FEE00-6003  Work edge detection error
2008-12-17 03:50        4006003        FEE00-6003  Work edge detection error
      如果上下相邻行报警内容相同,则把下一行删除,也就是要把红色字体部分删除,这个怎么做啊?
发表于 2009-12-1 21:05:05 | 显示全部楼层

  1. #!/bin/bash
  2. awk '
  3. BEGIN { ID=0 }
  4. {
  5.     if (ID != $3) {
  6.         ID=$3
  7.         printf "%s\n", $0
  8.     }
  9. } ' "$*"
复制代码

这样大概就可以了吧
回复 支持 反对

使用道具 举报

发表于 2009-12-1 21:13:36 | 显示全部楼层
发现这样也可以

  1. uniq --skip-chars=17 inputfile outputfile
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-12-1 22:04:12 | 显示全部楼层
谢谢大侠的指点,问题解决了!
回复 支持 反对

使用道具 举报

发表于 2009-12-2 00:07:17 | 显示全部楼层
uniq -f 2 filename
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表