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 kwalike57 <karinwalike@xxxxxxxxxxx> 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%

Where's the problem? Loop through the file using a standard while(){}.
When you find a line with a content that is eq()ual to '%Used' then read the
next line and check if the value is > 60.

How would I capture and evaluate only the %Used value and no other
values in that line?

That depends on what that line actually contains.
Standard answer: if you know the separator between values, then use split(),
if you know the value then use m/(...)/.

It is impossible to give more detailed suggestions without seeing the actual
data.

The 60% occurs first in the value line followed by a percent value for
inodes used.

That is nice, but a vague verbal description of the data can only result in
a vague verbal description of the algorithm.

jue
.



Relevant Pages