new2perl2016 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl Monks
Can somebody tell me how to get script to print out say the next few lines after a regex match? Currently I'm able to get the first line matched but nothing below it. My file contains these entries.
#Feb 19 15:22:21 206021 152221.684878 7219 INFO: Update certificate +for user=(XXX) , updated by XXX #Feb 19 15:22:21 206021 152221.694424 7220 INFO: MessageFromClient{m +sgId:UPDATE,state:{lastUpdatedDateTime:1427129443000,id:george,type:T +akerUser,lastUpdatedBy:xxx,partyDBId:TakemeHome,permissions:{perms:[P +rocess,SequesteredTrading],],r:0}}}}
#!/usr/bin/perl -w use strict; my $mesg = ""; #Feb 19 15:22:21 206021 152221.684878 7219 INFO: Update certificate +for user=(XXX) , updated by XXX #Feb 19 15:22:21 206021 152221.694424 7220 INFO: MessageFromClient{m +sgId:UPDATE,state:{lastUpdatedDateTime:1427129443000,id:george,type:T +akerUser,lastUpdatedBy:xxx,partyDBId:TakemeHome,permissions:{perms:[P +rocess,SequesteredTrading],],r:0}}}} my $search = "cat /pathtomydirectoryfiles/`date +%Y/%m/%d`/test/testlo +gs/*"; open FF, "$search |"; while (<FF>) { if (/Update certificate.*/){ #$count = 1 if /Updating certificate.*/; #if ($count >= 1 and $count <=2) { #next if /Updating certificate/; #print; #$count++; $mesg = "$_"; print $mesg; next; } } close FF;
Appreciate the assistance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to print 5 lines below after a regex match
by GotToBTru (Prior) on Feb 24, 2016 at 19:27 UTC | |
by new2perl2016 (Novice) on Feb 24, 2016 at 20:01 UTC | |
by poj (Abbot) on Feb 24, 2016 at 20:43 UTC | |
by Laurent_R (Canon) on Feb 24, 2016 at 21:30 UTC | |
|
Re: How to print 5 lines below after a regex match
by AnomalousMonk (Archbishop) on Feb 25, 2016 at 01:06 UTC | |
|
Re: How to print 5 lines below after a regex match
by FreeBeerReekingMonk (Deacon) on Feb 24, 2016 at 23:32 UTC |