Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: I wrote a script to grep

by davido (Cardinal)
on Jul 22, 2014 at 14:47 UTC ( [id://1094638]=note: print w/replies, xml ) Need Help??


in reply to I wrote a script to grep

I want the script to check the file for string "Response Queue Size: 0", and if this string has other than numerical 0, I want this to be print to my screen.

open my $infile, '<', 'C:/Users/katragas/Desktop/apadmin_get_status_lo +g.txt' or die $!; while( <$infile> ) { if( /Response Queue Size: (\d+)/ ) { print unless $1 == 0; } }

Your specification is fairly clear now; you've outlined the criteria. The next step is to implement those criteria:

  • Iterate over the lines of the file.
  • If a line matches "Response Queue Size: ", followed by a number, this is a line of interest.
  • If that number turns out to not be zero, print the line to your screen.

The code I provided above follows those three steps: The while loop iterates over the file, the 'if' statement looks for a pattern of interest, and the 'print unless' statement prints the line unless that line of interest has a number equal to zero associated with it.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1094638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-03-19 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found