Tamalero
Tamalero

Reputation: 471

A perl expression to grep until the appearance of one character combination

I have a very long string with this pattern:

34>>>Tamal234659 new tamal thing:01:34775 more tamal, for more tamal. etc...etc...etc...etc... 35>>>Tamal572934 old tamal thing:4c:33475 more tamal, for more tamal07. etc...etc...etc...etc... 35

I want to grep everything from the %d%d>>> until another %d%d>>> appears.

Like the \K trick but instead of forgetting the beginning, forgetting the ending.

Upvotes: 0

Views: 162

Answers (2)

Vijay
Vijay

Reputation: 67291

perl -lne 'print $2 if(/([\d]+)\>\>\>(.*) ([\d]+)\>\>\>.*/)' your_file

tested:

> cat temp
34>>>Tamal234659 new tamal thing:01:34775 more tamal, for more tamal. etc...etc...etc...etc... 35>>>Tamal572934 old tamal thing:4c:33475 more tamal, for more tamal07. etc...etc...etc...etc... 35

> perl -lne 'print $2 if(/([\d]+)\>\>\>(.*) ([\d]+)\>\>\>.*/)' temp
Tamal234659 new tamal thing:01:34775 more tamal, for more tamal. etc...etc...etc...etc...
> 

Upvotes: 1

fugu
fugu

Reputation: 6578

You can just use the following:

Input:

my @input =('34>>>Tamal234659 new tamal thing:01:34775 more tamal, for more tamal. etc...etc...etc...etc...35>>>Tamal572934 old tamal thing:4c:33475 more tamal, for more tamal07. etc...etc...etc...etc... 35');

my @lines;
foreach (@input){
    my @capture = ( $_ =~ /(\d+>>>.+)/g);
    push @lines, @capture;
}

Upvotes: 0

Related Questions