Help using regular expressions to parse complex log file.

M

Max Adams

All, I don't get on very well with reg exps at the best of times, and this
is proving to be very taxing to me.
I have a BIG log file which contins thousands of lines similar to this one:

[SERVER05] EnumServerProcesses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::Execute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options = 6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)

This is all one line in the log file. The data I want out from this one
line is:

"Stages.exe"
"begin PA_Stages.PR_GetProcessList:)TASKID)"
"11:59:29 27/08/2003"

Currently the closest reg exp I have at the moment is
my @extract = $_ =~ /^\[([^:]+).*?([^\\]+\.exe)\:/i;
But this only tries to get the process name and even this does not work with
the line above.
The server names in the example above are not guarenteed to be the same as
we have many machines and the path to the executable is not important to me,
just the process executable name.

Can anyone please help and give me some guide to the reg exp I need to be
using to get these 3 fields out of the file successfully.
PT
 
T

Tad McClellan

Max Adams said:
[SERVER05] EnumServerProcesses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::Execute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options = 6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)
The data I want out from this one
line is:

"Stages.exe"
"begin PA_Stages.PR_GetProcessList:)TASKID)"
"11:59:29 27/08/2003"
Can anyone please help and give me some guide to the reg exp I need to be
using to get these 3 fields out of the file successfully.


my @extract = $_ =~ /([^\\]+?\.exe):
.*?
SQL\s*=\s*begin\s+(.*?);\s*end;
.*?
SessionID\s*=\s*\d+\s*(\S+\s\S+)
/xi;
 
G

Garry Short

Max said:
All, I don't get on very well with reg exps at the best of times, and this
is proving to be very taxing to me.
I have a BIG log file which contins thousands of lines similar to this
one:

[SERVER05] EnumServerProcesses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::Execute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options =
6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)

This is all one line in the log file. The data I want out from this one
line is:

"Stages.exe"
"begin PA_Stages.PR_GetProcessList:)TASKID)"
"11:59:29 27/08/2003"

Currently the closest reg exp I have at the moment is
my @extract = $_ =~ /^\[([^:]+).*?([^\\]+\.exe)\:/i;
But this only tries to get the process name and even this does not work
with the line above.
The server names in the example above are not guarenteed to be the same as
we have many machines and the path to the executable is not important to
me, just the process executable name.

Can anyone please help and give me some guide to the reg exp I need to be
using to get these 3 fields out of the file successfully.
PT

@extract =
($_ =~ s/.*\\([^\\]+\.exe).*SQL = ([^;]+).* [0-9]{8} ([0-9: \/]+) .*/i);

The regex itself isn't pretty, but works with the example you've given.

HTH,

Garry
 
M

Max Adams

Both,

Thanks for your solutions however I have tried them and I have had only
partial success. One of the problems I have found is that the executable
name is not always guarenteed to be a fully qualified path. In the example
below it could just be entered into the log file in the format:
..... [SERVER06:Stages.exe:2588 .....

This does not work with the solutions given, can you please advise how I can
get this executable name regardless of if there is a path given or not
please.

PT



Garry Short said:
Max said:
All, I don't get on very well with reg exps at the best of times, and this
is proving to be very taxing to me.
I have a BIG log file which contins thousands of lines similar to this
one:

[SERVER05] EnumServerProcesses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::Execute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options =
6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)

This is all one line in the log file. The data I want out from this one
line is:

"Stages.exe"
"begin PA_Stages.PR_GetProcessList:)TASKID)"
"11:59:29 27/08/2003"

Currently the closest reg exp I have at the moment is
my @extract = $_ =~ /^\[([^:]+).*?([^\\]+\.exe)\:/i;
But this only tries to get the process name and even this does not work
with the line above.
The server names in the example above are not guarenteed to be the same as
we have many machines and the path to the executable is not important to
me, just the process executable name.

Can anyone please help and give me some guide to the reg exp I need to be
using to get these 3 fields out of the file successfully.
PT

@extract =
($_ =~ s/.*\\([^\\]+\.exe).*SQL = ([^;]+).* [0-9]{8} ([0-9: \/]+) .*/i);

The regex itself isn't pretty, but works with the example you've given.

HTH,

Garry
 
T

Tad McClellan

Max Adams said:


Who is "Both"?

Thanks for your solutions however I have tried them and I have had only
partial success.


The quality of the solution is directly proportional to the
quality of the specification.

You did not (and have not) tell us enough about your data to
make a solution that will work with all of your data, so all
we could do was make one that worked with the datum provided.

can you please advise how I can
get this executable name regardless of if there is a path given or not
please.



Please do not post the same question in multiple threads.

Now part of the discussion will be here and part will be
somewhere else...



[snip TOFU. Please do not do that either.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top