For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2005 > regex mutil-line matching









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regex mutil-line matching
Dermot Paikkos

2005-11-23, 6:56 pm

Hi

Looking at the mail queue on my smtp server I notice the usual amount
of crap. The mailq output is in this format:

11h 8.5K 1EeoEz-0003t2-00 <>
charlotte@pornomail.info

10h 10K 1EepGl-0004VH-00 <>
amy@pornomail.info

11h 8.4K 1EeoUI-0004YR-00 <>
eie@fromexotic.com

In case the formatting doesn't make it, that's a newline after '<>'
and a newlines between each (two-line) record.

I was hoping to do a one-liner that would yield just the message ID.
I tried a few variations but I couldn't get it.

mailq | perl -e 'while (<> ) {print $1, "\n" if /([\d+|\w+]-[\d+|\w+]-
00).*porn/m }'
# nothing at all.

mailq | perl -e 'while (<> ) {print $1, "\n" if /(\d+|\w+).porn/m }'
# Close but no cigar
#phoebe
#aimee
#yasmin
#poppy
#charlotte
#amy

mailq | perl -e 'while (<> ) {print $1, "\n" if /(.*-00).*porn/sm}'
# Nothing

I am missing something vital in my regex but I can't spot it. Any
advice?

TIA.
Dp.




Marcel

2005-11-23, 6:56 pm

Hi D.P.

Try this:

|perl -e 'while (<> ) {print "$1\n" if (/^\d+h\s.*\s(\w+-\w+-\w+)/);}'

Marcel

John W. Krahn

2005-11-23, 6:56 pm

Dermot Paikkos wrote:
> Hi


Hello,

> Looking at the mail queue on my smtp server I notice the usual amount
> of crap. The mailq output is in this format:
>
> 11h 8.5K 1EeoEz-0003t2-00 <>
> charlotte@pornomail.info
>
> 10h 10K 1EepGl-0004VH-00 <>
> amy@pornomail.info
>
> 11h 8.4K 1EeoUI-0004YR-00 <>
> eie@fromexotic.com
>
> In case the formatting doesn't make it, that's a newline after '<>'
> and a newlines between each (two-line) record.
>
> I was hoping to do a one-liner that would yield just the message ID.
> I tried a few variations but I couldn't get it.
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /([\d+|\w+]-[\d+|\w+]-
> 00).*porn/m }'
> # nothing at all.
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /(\d+|\w+).porn/m }'
> # Close but no cigar
> #phoebe
> #aimee
> #yasmin
> #poppy
> #charlotte
> #amy
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /(.*-00).*porn/sm}'
> # Nothing
>
> I am missing something vital in my regex but I can't spot it. Any
> advice?


Does this do what you want?

perl -l -00ane'print $F[2] if /porn/'



John
--
use Perl;
program
fulfillment
xicheng

2005-11-23, 6:56 pm

you may try this:

mailq | perl -ln00e 'print $1 if/(\w+)@/'

XC

Dermot Paikkos wrote:
> Hi
>
> Looking at the mail queue on my smtp server I notice the usual amount
> of crap. The mailq output is in this format:
>
> 11h 8.5K 1EeoEz-0003t2-00 <>
> charlotte@pornomail.info
>
> 10h 10K 1EepGl-0004VH-00 <>
> amy@pornomail.info
>
> 11h 8.4K 1EeoUI-0004YR-00 <>
> eie@fromexotic.com
>
> In case the formatting doesn't make it, that's a newline after '<>'
> and a newlines between each (two-line) record.
>
> I was hoping to do a one-liner that would yield just the message ID.
> I tried a few variations but I couldn't get it.
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /([\d+|\w+]-[\d+|\w+]-
> 00).*porn/m }'
> # nothing at all.
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /(\d+|\w+).porn/m }'
> # Close but no cigar
> #phoebe
> #aimee
> #yasmin
> #poppy
> #charlotte
> #amy
>
> mailq | perl -e 'while (<> ) {print $1, "\n" if /(.*-00).*porn/sm}'
> # Nothing
>
> I am missing something vital in my regex but I can't spot it. Any
> advice?
>
> TIA.
> Dp.


Marcel

2005-11-23, 6:56 pm

Hi john

Nice one!
How does it work? Would you mind explaining the syntax please..

Thanks,
Marcel

Marcel

2005-11-23, 6:56 pm

Hi john

Nice one!
How does it work? Would you mind explaining the syntax please..

Thanks,
Marcel

Jeff 'japhy' Pinyan

2005-11-23, 6:56 pm

On Nov 23, Dermot Paikkos said:

> Looking at the mail queue on my smtp server I notice the usual amount
> of crap. The mailq output is in this format:
>
> 11h 8.5K 1EeoEz-0003t2-00 <>
> charlotte@pornomail.info
>
> 10h 10K 1EepGl-0004VH-00 <>
> amy@pornomail.info
>
> 11h 8.4K 1EeoUI-0004YR-00 <>
> eie@fromexotic.com
>
> In case the formatting doesn't make it, that's a newline after '<>'
> and a newlines between each (two-line) record.


Well, if you read the file one line at a time, you'll never have BOTH a
message-ID AND an email address in a string at the same time. You'll need
to alter your input record seperator:

local $/ = ""; # matches on 2 or more newlines in a row

Or, from the command-line:

perl -00 ...

> mailq | perl -e 'while (<> ) {print $1, "\n" if /([\d+|\w+]-[\d+|\w+]-
> 00).*porn/m }'


Your regexes are funky. First of all, [...] is for CHARACTERS. [\d+|\w+]
is the same as [\d\w|+] which is the same as [\w|+] anyway, since \w
includes \d.

So you could do:

perl -00 -ane 'print $F[2] if $F[4] =~ /porn/' ...

The -a switch autosplits $_ into @F on whitespace.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://www.perlmonks.org/ % have long ago been overpaid?
http://princeton.pm.org/ % -- Meister Eckhart
xicheng

2005-11-23, 6:56 pm

guess I misunderstood his problem, i would in fact do the following:

mailq | perl -ln00e 'print $1 if/(\w+)@/'
------------
#phoebe
#aimee
#yasmin
-----------
mailq | perl -ln00e 'print $1 if/(\S+) <>/'
----
#1EeoEz-0003t2-00
#1EepGl-0004VH-00
#1EeoUI-0004YR-00
---
XC :)

Dermot Paikkos

2005-11-24, 7:56 am

On 23 Nov 2005 at 11:16, John W. Krahn wrote:
> Dermot Paikkos wrote:
> Hello,
>
>
> Does this do what you want?
>
> perl -l -00ane'print $F[2] if /porn/'
>


Thank you both. I should have mentioned that 'This is perl, version
5.003'. This might explain why I am not getting the results that I
should from both your replies. After a bit of tweaking I ended up
with

mailq | perl -l -00 -ane 'print $F[2]," ",$F[4],"\n" if /porn/'

which gives me

1Eeiiu-0001fc-00 phoebe@pornomail.info
A1Eejg0-0002cz-00 aimee@pornomail.info
A1EelBB-000341-00 yasmin@pornomail.info
A1EelLQ-0003S4-00 poppy@pornomail.info
A1EeoEz-0003t2-00 charlotte@pornomail.info
A1EepGl-0004VH-00 amy@pornomail.info

Which is what I want (I'll omit $f[4] later).

Of course in the long run I need upgrade my perl and install
spamassassin.

Thanx again.
Dp.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com