Holy mother of pe(a)rl! Here's your solution on the half shell. Sorry
for the bad puns - I'll clam up now.
grep -P -i '^125.*?baxp\.caed.*?\n250'
Documentation:
http://www.gnu.org/software/grep/doc/grep_6.html#SEC6
from gnu's grep --help
-P, --perl-regexp PATTERN is a Perl regular expression
Basic info sheet on Gnu's Grep
http://www.gnu.org/software/grep/grep.html
Demo (on windows where I don't need to quote the pattern):
C:\tmp>cat foo
125asdfasdfbaxp.caedasdfasdf
250 eat my shorts
250 eat my shorts
250 eat my shorts
C:\tmp>grep -P -i ^125.*?baxp\.caed.*?\n250 foo
125asdfasdfbaxp.caedasdfasdf
250 eat my shorts
Ranga Nathan wrote:
>Ok Kripa and Ben. It is a done deal.
>Why settle with the shell when you can get the pe(a)rl :-)
>Thanks. This script does not have to be super efficient but it has to be
>correct.
>I vote for Perl then.
>__________________________________________
>Ranga Nathan / CSG
>Systems Programmer - Specialist; Technical Services;
>BAX Global Inc. Irvine-California
>Tel: 714-442-7591 Fax: 714-442-2840
>
>
>
>
>Ben Tilly <btilly-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx>
>
>Sent by: boston-pm-bounces-PqP1ghmmPMdAfugRpC6u6w@xxxxxxxxxxxxxxxx
>10/19/2005 06:56 PM
>
>To
>Ranga Nathan <RNathan-Q9JuGO1wi3AS+FvcfC7Uqw@xxxxxxxxxxxxxxxx>
>cc
>boston-pm-PqP1ghmmPMdAfugRpC6u6w@xxxxxxxxxxxxxxxx
>Subject
>Re: [Boston.pm] Perl style regex in shell command for matching across
>lines?
>
>
>
>
>
>
>On 10/19/05, Ranga Nathan <RNathan-Q9JuGO1wi3AS+FvcfC7Uqw@xxxxxxxxxxxxxxxx>
>wrote:
>
>
>>I need to check ftp logs (see below) for successful transfer of files.
>>This is a bash script someone else wrote and I need to modify it. I want
>>to use a Perl style regex like
>>
>>/^125.*?baxp\.caed.*?\n250/i
>>
>> in any ?grep or sed or awk whichever can do this.
>>
>>I tried grep and egrep - they seem to match only one line at a time. I
>>
>>
>am
>
>
>>unable to match for \n inside the pattern.
>>
>>
>
>They only match one line at a time. That is what they do.
>
>
>
>>What shell utility would do it? I dont want to bring in the perl
>>interpreter just for this!
>>Thanks for the help.
>>
>>
>
>I would use Perl. But you can try this:
>
> grep -A 2 -i '^125.*baxp\.caed' FILE_HERE | grep -B 2 '^250'
>
>It will separate matches with lines containing --.
>
>Though if you want to do anything interesting with them, it would be
>easier to do it in Perl. Because EVERY tool in the basic Unix toolset
>assumes that "lines of data" are the data of interest, so data that
>goes across a line boundary is a PITA to handle.
>
>Cheers,
>Ben
>
>_______________________________________________
>Boston-pm mailing list
>Boston-pm-PqP1ghmmPMdAfugRpC6u6w@xxxxxxxxxxxxxxxx
>http://mail.pm.org/mailman/listinfo/boston-pm
>
>
>_______________________________________________
>Boston-pm mailing list
>Boston-pm-PqP1ghmmPMdAfugRpC6u6w@xxxxxxxxxxxxxxxx
>http://mail.pm.org/mailman/listinfo/boston-pm
>
>
>
--
Sincerely *Duane Bronson*
bronson-nLfnTIhOdZRl57MIdRCFDg@xxxxxxxxxxxxxxxx
<mailto:bronson-nLfnTIhOdZRl57MIdRCFDg@xxxxxxxxxxxxxxxx>
http://www.nerdlogic.com/
453 Washington St. #4A, Boston, MA 02111
617.515.2909
|