Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Fri, 28 Dec 2007 19:06:56 GMT
kwalike57 wrote:
I need to use Perl to read through log output from a df -k command on
a Unix server, for each line in the log where the value for %Used is
greater than 60% I need to write that line of the log out to another
text file. The header %Used is located on the line above the actual
value, like this:
%Used
60%
How would I capture and evaluate only the %Used value and no other
values in that line?
The 60% occurs first in the value line followed by a percent value for
inodes used.
open my $ph, '-|', 'df', '-k' or die "Cannot open pipe from 'df' $!";
<$ph> =~ /%used?\b|\bused?%/i and my $pos = $-[0];
/\A.{$pos}\s*(\d+)/ && $1 > 60 && print while <$ph>;
close $ph or warn $! ? "Error closing 'df' pipe: $!"
: "Exit status $? from 'df'";
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- Follow-Ups:
- References:
- Prev by Date: Re: count the number of occurences of each different word of a text
- Next by Date: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
- Previous by thread: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
- Next by thread: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
- Index(es):
Relevant Pages
|