0

我有一个很长的字符串,这个模式:

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

我想从 %d%d>>> grep 一切,直到另一个 %d%d>>> 出现。

就像 \K 技巧,但不是忘记开头,而是忘记结尾。

4

2 回答 2

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

测试:

> 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...
> 
于 2013-11-11T10:21:44.610 回答
0

您可以使用以下内容:

输入:

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;
}
于 2013-11-11T09:41:39.193 回答