免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1736 | 回复: 8
打印 上一主题 下一主题

求大侠帮忙(文本处理问题) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-01 18:55 |只看该作者 |倒序浏览
各位大侠好:
      我有一个文本文件,和下面的一样,每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
      如果上下相邻行报警内容相同,则把下一行删除,也就是要把红色字体部分删除,这个怎么做啊?

[ 本帖最后由 zhuyongxin 于 2009-12-1 19:18 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-12-01 19:40 |只看该作者

回复 #1 zhuyongxin 的帖子

awk '!a[$3]++'

论坛徽章:
0
3 [报告]
发表于 2009-12-01 19:57 |只看该作者
perl -ane '$i[$.]=$F[2];$s=$i[($.-1)];if ($F[2] ne $s){print "$_"}'  file

论坛徽章:
0
4 [报告]
发表于 2009-12-01 20:50 |只看该作者
各位大侠好,我需要把相邻行报警内容相同的只保留一行。
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: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: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:50        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:50        2006036        LD200-6036  Loader frame pusher forward error.

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
5 [报告]
发表于 2009-12-01 20:55 |只看该作者
try
  1. uniq -f 3 urfile
复制代码

论坛徽章:
0
6 [报告]
发表于 2009-12-01 21:38 |只看该作者
问题解决了,谢谢各位大侠的热心帮助!

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
7 [报告]
发表于 2009-12-01 21:41 |只看该作者

回复 #6 zhuyongxin 的帖子

怎么解决的?说出来让大家分享分享啊。

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
8 [报告]
发表于 2009-12-01 22:14 |只看该作者
uniq

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
9 [报告]
发表于 2009-12-01 22:25 |只看该作者

回复 #2 wtuter 的帖子

这样会把不相邻的重复行也删掉。uniq命令正合适,估计楼主用的就是黑哥的方案。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP