arpita has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am beginner to Perl. Needs a help on processing the log file.

Here is the content of file.

2015-03-27 20:39:49,796 ERROR MPesa 7002 webServices 10.201.12.200- [M +P27203801969209][301a8a0e-bb59-4182-9a4b-79abbb3ed39a][payBillRecharg +eAllOperator][McomSendSMSServiceImpl][callSpiceSMSApi] - Exit Method +with status Map : {smsFlag=true, errorMsgs=null, status=SUCCESS} for +msisdn : 9431641426 2015-03-27 20:39:49,796 ERROR MPesa 7002 webServices 10.201.12.200- [M +P27203801969209][301a8a0e-bb59-4182-9a4b-79abbb3ed39a][payBillRecharg +eAllOperator][SmsDataHelper][setSmsData] - Exiting method setSmsData +for Msisdn : 9431641426 with SMS Flg : true

In above file I need to check for the Pattern [MP27203801969209] and pick that value and the corresponding 9431641426 value in the end. Picking these value I need to put this combination in another file. Also value "[MP27203801969209]" is not hard coded so I have to check for this block [MP[1-9]] in each line.

Please suggest the perl code for the same.

Replies are listed 'Best First'.
Re: Perl Regular Expression Issue
by Corion (Patriarch) on Sep 07, 2015 at 11:04 UTC

    What code have you already written and how does it fail to do what you need?

    This site is for learning Perl, not for writing code on request, so please help us help you by providing the code you already have and telling us where you encounter problems.

Re: Perl Regular Expression Issue
by AnomalousMonk (Archbishop) on Sep 07, 2015 at 13:39 UTC
Re: Perl Regular Expression Issue
by u65 (Chaplain) on Sep 07, 2015 at 12:31 UTC

    In addition to Corion's advice, it would help if you put your example data file inside code tags.

Re: Perl Regular Expression Issue
by NetWallah (Canon) on Sep 08, 2015 at 01:00 UTC
    Here is a one-liner to get you started:
    perl -E 'my ($datetime, $mpnum, $msisdn) = $ARGV[0]=~/^([\d\-]+\s[\d:,]+).+\[MP(\d{14})\].+msisdn\s:\s(\d+)/; say for ($datetime,$mpnum,$msisdn)' '2015-03-27 20:39:49,796 ERROR MPesa 7002 webServices 10.201.12.200- [ +MP27203801969209][301a8a0e-bb59-4182-9a4b-79abbb3ed39a][payBillRechar +geAllOperator][McomSendSMSServ­iceImpl][callSpiceSMSApi] - Exit Metho +d with status Map : {smsFlag=true, errorMsgs=null, status=SUCCESS} fo +r msisdn : 9431641426' __Output__ 2015-03-27 20:39:49,796 27203801969209 9431641426

            Clarity: it's like that one thing that is not the other thing, except for when it is.

      Thanks a lot for the help. It worked!!