logo       

Re: [Boston.pm] Perl style regex in shell command for matching across lines: msg#00077

Subject: Re: [Boston.pm] Perl style regex in shell command for matching across lines?
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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe