Re: find lines in a file



On Feb 16, 11:40 am, "jesse" <jesse_ha...@xxxxxxxxxxxxxx> wrote:
On Feb 14, 11:17 am, "jesse" <jesse_ha...@xxxxxxxxxxxxxx> wrote:
On Feb 14, 10:37 am, "Paul Lalli" <mri...@xxxxxxxxx> wrote:
On Feb 14, 10:20 am, "jesse" <jesse_ha...@xxxxxxxxxxxxxx> wrote:
On Feb 6, 3:22 pm, "Paul Lalli" <mri...@xxxxxxxxx> wrote:
while (<DATA>) {
if (/Error: (.*)/) {
$count_of{$1}++;
}}
Paul, I have a question. The (.*) is supposed to capture everything
after thematchright? So if I didn't want to capture everything
after thematchcould this be changed some how to just grab the next
35charactersafter thematchorbeforethematch?

if (/Error: (.{35})/) {

I have found that what you have given still isn't quite what I need.

I gave you exactly what you *asked for*. I am not a mind reader. If
you don't need what you ask for, or if you don't ask for what you
need, there's really very little I can do about it.

I have read most of the perldoc on regular expressions but I'm still
not sure how to fix it. The log files needless to say are not a fix
length or width.

Then why did you ask very specifically for 35 characters after a given
match?

Here is a couple of line from one of the log files.

00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
(5), premature end of file encountered
00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
= socket read failed (23)
00:04:21.876 [775] <2> listen_loop: select() interrupted

What I would like for the script to do is ignore everything up to the
<2> and just process the line after that.

I have no idea what you mean by "process the line after that." If you
want the text that comes after the "<2>", then just get it:

if ($line =~ /<2>\s*(.*)/) {
my $error = $1;
#do whatever you want with $error;
}


[snip long complicated code snippet]

You need to work on posting short-but-complete scripts that
demonstrate *just* the problem at hand, and remove all the other
cruft. For example:

#!/usr/bin/perl
use strict;
use warnings;

while (my $line = <DATA>) {
if ($line =~ /<2>\s*(.*)/) {
my $error = $1;
print "The error is: '$error'\n";
}
}
__DATA__
00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
(5), premature end of file encountered
00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
= socket read failed (23)
00:04:21.876 [775] <2> listen_loop: select() interrupted


Output:
The error is: 'get_bprdresp: get_string() failed, I/O error (5),
premature end of file encountered'
The error is: 'process_request: get_hostinfo failed - status = socket
read failed (23)'
The error is: 'listen_loop: select() interrupted'


Modifying the above for your own needs is left as an excercise for
you.

Paul Lalli

.