Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: command line perl command to get between lines with non greedy match

by LanX (Archbishop)
on Jan 17, 2020 at 23:25 UTC ( #11111559=note: print w/replies, xml ) Need Help??


in reply to command line perl command to get between lines with non greedy match

I probably misunderstood your problem, this works in printing the last shortest match between 1 and 3
C:\tmp\files>perl -ne"@out=() if /PATTERN1/; push @out,$_ if /PATTERN1 +/../PATTERN3/; END{ print @out }" input PATTERN1 SOME INFO TEXT4 TEXT5 TEXT6 PATTERN3 SOME INFO C:\tmp\files>

NB: for linux you'll need to replace " to '

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re: command line perl command to get between lines with non greedy match
  • Download Code

Replies are listed 'Best First'.
Re^2: command line perl command to get between lines with non greedy match
by LanX (Archbishop) on Jan 18, 2020 at 02:05 UTC
    This will print all shortest records between Pattern 1 and 3

    I just doubled your input.

    C:\tmp\files>perl -nE"if ($x=(/PATTERN1/../PATTERN3/)) { @out=() if /P +ATTERN1/; push @out,$_; print @out if $x=~/E0$/ }" input2 PATTERN1 SOME INFO TEXT4 TEXT5 TEXT6 PATTERN3 SOME INFO PATTERN1 SOME INFO TEXT4 TEXT5 TEXT6 PATTERN3 SOME INFO C:\tmp\files>

    update

    a bit cleaner

    C:\tmp\files>perl -nE" $first=/PATTERN1/; $last=/PATTERN3/; if ( $firs +t..$last) { @o=() if $first; push @o,$_; say @o if $last }" input2 PATTERN1 SOME INFO TEXT4 TEXT5 TEXT6 PATTERN3 SOME INFO PATTERN1 SOME INFO TEXT4 TEXT5 TEXT6 PATTERN3 SOME INFO

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2020-02-26 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (117 votes). Check out past polls.

    Notices?