File Parsing

(imported topic written by Steve73)

Hi Guys

Having trouble getting my head around this so help would be appreciated.

I need to query a file for a particular entry and pull out that line, the previous line and the following four lines. The enties may also be seen multiple times with different values, although one line will always be constant in the “block”

For instance, the below entries may appear in the log file, they all have one consistent line (Entry Type=WARNING)

How do I then pull this line, the previous line and the following four lines for each time the (Entry Type=WARNING) is seen in the log?:

Date : xx/xx/xxxx Time : xx:xx:xx

Entry Type=WARNING

File: abcdefg, Line: 2345

Details : Machine was rebooted unexpectedly and the component UninstallKey was not found

Component will not be added to software inventory.

Type: Component, Name: abc123


Date : xx/xx/xxxx Time : xx:xx:xx

Entry Type=WARNING

File: zzzzzzzzzzzzzzzzzz, Line: 1234

Details : Machine was rebooted unexpectedly and the component UninstallKey was not found

Component will not be added to software inventory.

Type: Component, Name: zzzzzzzzzzzzzzzz

I’ve been playing around with next line, previous line etc…but not getting very far forward at the moment due to the multiple entries

Cheers

Steve

(imported comment written by Lee Wei)

Hi Steve,

Here are some example statements for you to try.

The last one is the one we want.

q: lines (1; 2) of file "c:\temp\test.txt"
 
q: (it-1; it; it+1; it+2; it+3; it+4) of line numbers of lines whose (it starts with "Entry Type=WARNING") of file "c:\temp\test.txt"
 
q: lines ((it-1; it; it+1; it+2; it+3; it+4) of line numbers of lines whose (it starts with "Entry Type=WARNING") of file "c:\temp\test.txt") of files "c:\temp\test.txt"

Lee Wei

(imported comment written by Steve73)

Perfect Lee…thanks!