我想解析这组行,这样如果在连续行中获得与**<yagyavalkbhatt@yahoo.com>**
相同的模式,它应该在两者之间用“,”打印它。
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>
<yagyavalkbhatt@yahoo.com>
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>
<yagyavalkbhatt@yahoo.com>
我怎样才能在Perl中做到这一点?
答案 0 :(得分:2)
环顾四周:
#!/usr/bin/env perl
use strict;
use warnings;
my $str = <<'EOS';
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>
<yagyavalkbhatt@yahoo.com>
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>
<yagyavalkbhatt@yahoo.com>
EOS
$str =~ s/(?<=<yagyavalkbhatt\@yahoo.com>)\s+(?=<yagyavalkbhatt\@yahoo.com>)/,/g;
print $str;
输出:
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>,<yagyavalkbhatt@yahoo.com>
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<yagyavalkbhatt@yahoo.com>,<yagyavalkbhatt@yahoo.com>