Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?



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.
.



Relevant Pages

  • Re: syntax...
    ... B&D on the part of the language designer. ... probably handle concatenation of string literals by itself, ... bitwise XOR, or if not that, then exponentiation.) ...
    (comp.lang.misc)
  • Bugs in the Module::Dependency
    ... Manifying blib/man1/pmd_indexer.plx.1 ... Use of uninitialized value in concatenation or string at ... # Failed test in t/04grapher.t at line 81. ...
    (perl.dbi.users)
  • RE: Simple regex problem has me baffled
    ... I am writing a script to analyse a log file. ... Each pair of Request and Response calls have a unique ... Use of uninitialized value in concatenation or string at ...
    (perl.beginners)
  • Re: Literal concatenation, strings vs. numbers (was: Numeric literals in other than base 10 - wa
    ... Well my take on it is that this would not be the same as string ... concatenation, the series of digits would be parsed as a single token ... digit separation can superficially resemble string concatenation if ... I would favor _ as a digit separator in Python ...
    (comp.lang.python)
  • Re: Simple regex problem has me baffled
    ... I am writing a script to analyse a log file. ... Each pair of Request and Response calls have a unique ... Use of uninitialized value in concatenation or string at ./magic.pl ...
    (perl.beginners)