Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: perl one line for advanced grep (current line and next one)

by kschwab (Priest)
on Sep 02, 2013 at 04:43 UTC ( #1051884=note: print w/ replies, xml ) Need Help??


in reply to perl one line for advanced grep (current line and next one)

perl -ne 'print $_.=<> if /string/' testfile


Comment on Re: perl one line for advanced grep (current line and next one)
Download Code
Replies are listed 'Best First'.
Re^2: perl one line for advanced grep (current line and next one)
by Random_Walk (Prior) on Sep 02, 2013 at 08:03 UTC

    Nice, but it misses the line following a second consecutive line matching the pattern

    # eg this works as expected test1 string test2 test3 # this one fails to print test2 test1 string string test2 test3

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
      It also hangs if the last line matches. So much for working off the top of my head.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2015-08-28 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (335 votes), past polls