2

我有一个从 PLC 转储的每日日志文件,示例文本是(它没有标题,只有原始数据):

5/29/2009 3:05:33 PM: PLC Requested Hand Scan
5/29/2009 3:05:40 PM: HH Label Data Retrieved: 078797312
5/29/2009 3:05:40 PM: PLC Requested Scale Weight
5/29/2009 3:05:40 PM: Scale Data Retrieved:    56.0
5/29/2009 3:05:40 PM: ProcessMOSData Loop: 1
5/29/2009 3:05:40 PM: About to read
5/29/2009 3:05:40 PM: Read: False
5/29/2009 3:05:40 PM: ProcessMOSData Loop: 2
5/29/2009 3:05:40 PM: About to read
5/29/2009 3:05:40 PM: Read: True
5/29/2009 3:05:40 PM: Found Bin02
5/29/2009 3:05:40 PM: ProcessMOSData Loop: 3
5/29/2009 3:05:40 PM: About to read
5/29/2009 3:05:40 PM: Read: False
5/29/2009 3:05:40 PM: ProcessMOSData Loop: 4
5/29/2009 3:05:40 PM: About to read
5/29/2009 3:05:40 PM: Read: False
5/29/2009 3:05:40 PM: ProcessMOSData Loop: 5
5/29/2009 3:05:40 PM: About to read
5/29/2009 3:05:41 PM: Read: False
5/29/2009 3:05:41 PM: ProcessMOSData Loop: 6
5/29/2009 3:05:41 PM: About to read
5/29/2009 3:05:41 PM: Read: False
5/29/2009 3:05:41 PM: ProcessMOSData Loop: 7
5/29/2009 3:05:41 PM: About to read
5/29/2009 3:05:41 PM: Read: False
5/29/2009 3:05:41 PM: ProcessMOSData Loop: 8
5/29/2009 3:05:41 PM: About to read
5/29/2009 3:05:41 PM: Read: False
5/29/2009 3:05:41 PM: ProcessMOSData Loop: 9
5/29/2009 3:05:41 PM: About to read
5/29/2009 3:05:41 PM: Read: False
5/29/2009 3:05:41 PM: Got all data
5/29/2009 3:05:41 PM: Wrote good label ack

我有 15 个“关键短语”要数一数。我有 1150 个文本文件,我可能会将它们组合成一个大文本文件,然后在初始读取后将其读取并转储到新表中。它可以输出到 csv 或 sql,并不重要。最后一部分将只是监控流程变更的改进如何提高该领域的效率。

例如,其中一个关键短语是“PLC 请求手部扫描”,因此在示例中它将有 2009 年 5 月 29 日 1 次。我在想顶部的标题将是关键短语,而左侧将是不同的日子。这似乎是 logparser 可以做的事情,但是如果没有标题并且每一行只是一个长字符串,我不知道如何开始。

4

1 回答 1

0

YES, you can solve this using LogParser. To get the right query easyly install LogParser Lizard, its a simple and free tool for you to test your queries at Logparser, before coding.

Set Logparser input to TEXTLINE input format.

At the FROM clause you can contatenate as many files as you want, like this FROM 'filename', 'filename2', 'filename3' and so on (all must have same structure)

Here is a logparser query that will help you to start

SELECT extract_token(Text,0,' ') AS Date,
       strcat(extract_token(extract_token(Text,1,' '),0,'PM: '),' PM') AS Time,
       extract_token(Text,1,'PM: ') AS MSG
FROM 'F:\test.txt'

Also you can group by msg doing this

SELECT extract_token(Text,1,'PM: ') AS MSG
FROM 'F:\test.txt'
GROUP BY MSG
于 2013-10-05T03:45:36.577 回答