LinuxSir.cn,穿越时空的Linuxsir!

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

[提问]如何去掉调试信息的重复行(较难)

[复制链接]
发表于 2007-12-25 19:03:58 | 显示全部楼层 |阅读模式
如下:
Dec 25 15:55:51 : iscsi_tx_1 UnsolData 0, data_len 4096, data_done 0, r2t_data_left 0
Dec 25 15:55:51 :     ITT: 0xffffffff
Dec 25 15:55:51 : Leave do_iscsi_rx_data
Dec 25 15:55:51 : Leave free_r2t_cookie
Dec 25 15:55:51 : Leave free_targ_buf
Dec 25 15:55:51 : Leave handle_iscsi_rx_data
Dec 25 15:55:51 :     MaxCmdSN: 22243
Dec 25 15:55:51 :     Opcode: 0x00,  I: 1
Dec 25 15:55:51 :     Opcode: 0x20,  I: 0
Dec 25 15:55:51 : scsi cmnd 00000000, init_task_tag -1 target_xfer_tag 21 data_done 0 xfer length 0
Dec 25 15:55:51 : Search found the command
Dec 25 15:55:51 : set dequeue command statsn 19, received exp_stat_sn 20, command state 5
Dec 25 15:55:51 :     StatSN: 20
Dec 25 15:55:51 :     TTT: 21
。。。。
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
+++++++++++++++++++++++++=
输出:
Dec 25 15:55:51 : iscsi_tx_1 UnsolData 0, data_len 4096, data_done 0, r2t_data_left 0
Dec 25 15:55:51 :     ITT: 0xffffffff
Dec 25 15:55:51 : Leave do_iscsi_rx_data
Dec 25 15:55:51 : Leave free_r2t_cookie
Dec 25 15:55:51 : Leave free_targ_buf
Dec 25 15:55:51 : Leave handle_iscsi_rx_data
Dec 25 15:55:51 :     MaxCmdSN: 22243
Dec 25 15:55:51 :     Opcode: 0x00,  I: 1
Dec 25 15:55:51 :     Opcode: 0x20,  I: 0
Dec 25 15:55:51 : scsi cmnd 00000000, init_task_tag -1 target_xfer_tag 21 data_done 0 xfer length 0
Dec 25 15:55:51 : Search found the command
Dec 25 15:55:51 : set dequeue command statsn 19, received exp_stat_sn 20, command state 5
Dec 25 15:55:51 :     StatSN: 20
Dec 25 15:55:51 :     TTT: 21
。。。
Dec 25 15:52:51 : iscsi_tx_1 awake, session c8534d80, conn c3874e80
Dec 25 15:52:51 : iscsi_tx_1 handled 0 commands
需要将这些2行一重复的去掉(时间不相同的也算重复的),当然保留一份更好。
不要简单的以为用cat file | uniq就可以了,这是2行一重复。
也不要改变时间顺序。
实际出现的问题,若有人能写出来,感激不尽!

如果不行,只去掉文件中的带iscsi_tx_1 awake和scsi_tx_1 handled 0 commands的行也可以
发表于 2007-12-25 19:46:00 | 显示全部楼层
  1. awk -v FIELDWIDTHS='18 1024 1' '!($2~/^iscsi_tx_1/&&a[$2]++)' 数据文件
复制代码

分析,文件的格式似乎是   时间 : 信息  而 "时间 : " 这部分一共18个字符的宽度

而gawk有FIELDWIDTHS这个特性,即可以用固定宽度来分解字段
第二个字段设置为1024,估计这个长度应该足够了,如果觉得不够的话,可以再用更大的数目

!($2~/^iscsi_tx_1/&&a[$2]++)  如果分解后的第二字段出现重复的话(并且第二字段以iscsi_tx_1打头),就不输出
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-25 21:59:33 | 显示全部楼层
谢谢springwind426!

&&a[$2]++是判断与下一行是否相同的吗?不过好像在这里不行,这里是两行重复
^iscsi_tx_1去掉了一些有用的信息
++++++++++++++++
根据你的提示,修改了下:
awk -v FIELDWIDTHS='18 1024' '!($2~/awake/||/handled 0 command/)' log_target.txt > my.txt

+++++++++++++++++++++
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[2] c3d6c000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 2, ITT 88897, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 handled 2 commands
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[1] c27f4000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 1, ITT 88896, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[2] c3d6c000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 2, ITT 88897, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 handled 2 commands
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[1] c27f4000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 1, ITT 88896, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[2] c3d6c000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 2, ITT 88897, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 handled 2 commands
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[1] c27f4000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 1, ITT 88896, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 pick up cmnd[2] c3d6c000
Dec 25 15:55:46 : iscsi_tx_1 handle cmnd no. 2, ITT 88897, opcode 0x01, state 5
Dec 25 15:55:46 : iscsi_tx_1 UnsolData 0, data_len 1024, data_done 1024, r2t_data_left 0
Dec 25 15:55:46 : iscsi_tx_1 handled 2 commands
+++++++++++++++++++++++++++
居然发现了3行一起重复的,郁闷。
awk中可否判断一个域与下2行或下3行是否相等的?
回复 支持 反对

使用道具 举报

发表于 2007-12-26 21:04:07 | 显示全部楼层
介绍一下我的想法.可能很复杂.
1)先用sed先将每行的行头行尾加上特殊字符%%即
%%  ....                  %%
2)每两行插入一个空的新行
3)在awk,设置记录的分隔符,%%作为域的分隔符,输出所有的域作一个新的文件,即重复的两行变为一行,然后用quin即可以删除重复行.最后然后利用设置了的%%分隔符,将删除来哦重复行的文件恢复文件.
当然,利用awk作编程也是可以实现的
回复 支持 反对

使用道具 举报

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

本版积分规则

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