Reputation: 471
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
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
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