标题说的很对。基本上,我试图压缩一个巨大的日志文件。
Notepad ++和Regex(我知道一点)可以删除这些重复的行,但是问题是,我不想将它们全部删除。我希望保留一个实例,以保留日志消息的结构/顺序。
我GOOGLE了很多的答案,但我似乎只得到这样的结果这样。问题是我不只是尝试替换或排除行。
在这一点上,我猜想Regex更有可能给出答案,但是我还处在那个阶段,我不知道可以使用哪些工具。
编辑:
我有成千上万条消息的示例,但只需要查看其中之一:(我看到了其中的很多,因为每个scsi设备都希望在自己的消息中加入芯片。我只需要看到它正在发生,而不是它正在发生给他们每个人)。
multipathd[4893]: 3600a098000badf6800005dfe5a8cd2cd: sdie - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000badf6800005def5a8cd273: sdgq - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000badf6800005df05a8cd27b: sdeq - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000bae10c00005df55a8cd2ec: sdgw - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000bae10c00005df05a8cd2c2: sdfk - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000bae10c00005dec5a8cd2a3: sdgm - rdac checker reports path is down: ctlr is in startup sequence multipathd[4893]: 3600a098000badf6800005df35a8cd292: sdfo - rdac checker reports path is down: ctlr is in startup sequence
但我想看看
rdac checker reports path is down: ctlr is in startup sequence
如果多个实例是连续的,则可以执行以下操作:
根据新要求更新:
^([^-]+- )(.+)(?:\R(?1)\2)+
$2
. matches newline
解释:
^ : beginning of line
( : start group 1
[^-]+- : 1 or more NOT dash,then a dash and a space
) : end group 1
( : start group 2
.+ : 1 or more any character
) : end group 2
(?: : start non capture group
\R : any kind of linebreak
(?1) : same pattern than group 1 (ie. "[^-]+- ")
\2 : backreference to group 2
)+ : end non capture group, must appears 1 or more times.
替代:
$2 : content of group 2
给定示例的结果:
rdac checker reports path is down: ctlr is in startup sequence
如果多个实例不是连续的,则最好使用自己喜欢的脚本语言编写一个脚本。
这是完成此工作的perl一线客:
perl -aE 'chomp;(undef,$x)=split(/-/,$_);next if exists $s{$x};$s{$x}=1;say$x' inputfile
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句