English 中文(简体)
通过界定reg
原标题:filter log file by defining regexes

我拥有一些匈牙利地理统计局记录(50Mb;~500K项目)。 我需要开始过滤一些碎片。 日志文件正在使用日志4j制作,基本模式是:

[log-level] date-time class etc, etc  
log-message  

我looking想一种方式,即我可以确定一个reg开端和reg末(或其他类似),从档案中筛选出相应的条目,以便我更容易地通过这些庞大的档案。 我的想法是,起顶层是原木级,而最终层是原木。 我确信,我可以撰写一个支离破碎的方案,以完成这项任务,但我认为我是在走这条道路之前向社区提出。 提前感谢。


让我谈谈我的问题。 请允许我在我的记录中假设以下幻灯:

[DEBUG] date-time class etc, etc  
log-message-1

[WARN] date-time class etc, etc  
log-message-2

[DEBUG] date-time class etc, etc  
log-message-3

[DEBUG] date-time class etc, etc  
log-message-1

[WARN] date-time class etc, etc  
log-message-2

[DEBUG] date-time class etc, etc  
log-message-6

我这样一来,就能够过滤原木。

[DEBUG] date-time class etc, etc  
log-message-3

[DEBUG] date-time class etc, etc  
log-message-6

我希望能做到这一点,就是确定一些 sets格模式。 在我的上述例子中,我想要确定一个表象,用于记录Entry1,另一个用于记录Entry2。

我希望这有助于澄清我的问题。

最佳回答

假设<代码>log-message-1和log-message-2和独特模式。

$ awk -vRS=  !/log-message-[12]/  ORS="

" file
[DEBUG] date-time class etc, etc
log-message-3

[DEBUG] date-time class etc, etc
log-message-6
问题回答
(zyx:~) % echo $T
[DEBUG] date-time class etc, etc  
log-message-1

[WARN] date-time class etc, etc  
log-message-2

[DEBUG] date-time class etc, etc  
log-message-3

[DEBUG] date-time class etc, etc  
log-message-1

[WARN] date-time class etc, etc  
log-message-2

[DEBUG] date-time class etc, etc  
log-message-6
(zyx:~) % echo $T | perl -e  $_=join("", <>); s/[DEBUG][^
]*
(log-message-1|log-message-2).*?(?=
[(DEBUG|WARN)]|$)//sg; s/[WARN].*?(?=
[(DEBUG|WARN)]|$)//sg; print; 


[DEBUG] date-time class etc, etc  
log-message-3



[DEBUG] date-time class etc, etc  
log-message-6

使用<条码>wk或一流式。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签