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: nolo contendere <simon.chao@xxxxxxx>
- Date: Fri, 28 Dec 2007 11:16:38 -0800 (PST)
On Dec 28, 2:06 pm, "John W. Krahn" <some...@xxxxxxxxxxx> wrote:
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'";
That's pretty nifty (no sarcasm intended). However, have you tried
it?
I don't get what I expect. Perhaps the issues are on my end though...
bash-2.03$ ./df.pl
df: cannot statvfs /foswbdmmk1/install: Permission denied
df: cannot statvfs /foswbdmmk1/admin: Permission denied
df: cannot statvfs /foswbdmmk1/was: Permission denied
df: cannot statvfs /foswbdmmk1/stag: Permission denied
df: cannot statvfs /foswbdmmk1/prev: Permission denied
df: cannot statvfs /foswbdmmk1/log: Permission denied
df: cannot statvfs /foswbdmmk1/ihs: Permission deniedUse of
uninitialized value in concatenation (.) or string at ./df.pl line 10,
<$ph> line 2.
df: cannot statvfs /foswbdmmk1/app: Permission denied
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 3.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 4.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 5.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 6.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 7.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 8.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 9.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 10.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 11.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 12.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 13.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 14.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 15.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 16.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 17.
Use of uninitialized value in concatenation (.) or string at ./df.pl
line 10, <$ph> line 18.
.
- References:
- Prev 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?
- Next by Date: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- 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: FAQ 5.33 How do I close a file descriptor by number?
- Index(es):
Relevant Pages
|