in reply to Re: Perl Extract specific string
in thread Perl Extract specific string

Thanks CountZero !!!

please help me again.

#!/usr/bin/perl use warnings; use strict; my $str = <<'_STR_'; 09.05.2014 09.49.52:359 RID:routerNode1@app1:1662306081,msisdn:7878872 +25696,sid:93889095007001,tid:1405090902095648846024000,status:2,time: +20140509094952,reason:DELIVRD,refund:null,status2:null _STR_ my $wanted_data; for ( split /,/, $str ) { if (/(\d{2}\.\d{2}\.\d{4}' '\d{2}\.\d{2}\.\d{2}).+RID:(\d+)/sm) { my ( $format_date, $rid )= ( $1, $2 ); $format_date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/; $wanted_data .= $format_date . ',' . $rid; } elsif (/msisdn:(.+)/) { $wanted_data .= ',' . $1; } elsif (/sid:(.+)/) { $wanted_data .= ',' . $1; } elsif (/tid:(.+)/) { $wanted_data .= ',' . $1; } elsif (/status:(.+)/) { $wanted_data .= ',' . $1; } elsif (/time:(.+)/) { $wanted_data .= ',' . $1; } else{ print "data given is not true"} } print $wanted_data, $/;

the wanted_data like this below :

09-05-2014,09-49-52,routerNode1@app1:1662306081,787887225696,93889095007001,1405090902095648846024000,2,20140509094952

when run, error like below:

data given is not truedata given is not truedata given is not truedata given is not true,787887225696,93889095007001,1405090902095648846024000,2,20140509094952

and please advice, how to read the input file and write to the output file.

Thank you.