Re: find lines in a file
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 16 Feb 2007 10:08:07 -0800
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>) {Paul, I have a question. The (.*) is supposed to capture everything
if (/Error: (.*)/) {
$count_of{$1}++;
}}
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
.
- Follow-Ups:
- Re: find lines in a file
- From: jesse
- Re: find lines in a file
- References:
- find lines in a file
- From: jesse_hardy
- Re: find lines in a file
- From: Paul Lalli
- Re: find lines in a file
- From: jesse
- Re: find lines in a file
- From: Paul Lalli
- Re: find lines in a file
- From: jesse
- Re: find lines in a file
- From: jesse
- find lines in a file
- Prev by Date: Re: find lines in a file
- Next by Date: Re: Automated testing of cgi / perl
- Previous by thread: Re: find lines in a file
- Next by thread: Re: find lines in a file
- Index(es):