[Za-pm] Script

Oskar Pearson oskar at qualica.com
Wed Jun 4 08:05:50 CDT 2003


Hi


> Your assumption that the log lines are wrapped is correct. If I use my 
> previous bash script I get the same as with this perl script that you 
> suggest.
> 
> I need to filter this file in such a manner that it only displays the 
> email of the person that the mail originated from and obviously there 
> might be more than one email address. If I use
> awk '{print $8, $9, $10}' it returns the values for column 8, 9 and 10 
> from the input file. What I want is to only have the emails 
> (user1 at domain.co.za, user2 at domain.co.za etc.) to be filtered to an 
> output file which I could use for accountting purposes.
> 
> Does this make more sense??


So you basically want to discard the date and length and stuff,
and simply get the addresses?

while (<STDIN>) {
        my ($email_address) = $_ =~ /([^\s<]+\@[^\s>]+)/;
        print "email_address: $email_address\n";
}


The above means:

assign to variable $email_address any sequence of strings
that has the format of:

one or more [non-space or non-< characters] followed by an
@sign, followed by one or more [non-space and non-> characters]

oskar at core1:~$ perl t.pl < t.txt
email_address: user at domain.co.za
email_address: user at domain.co.za
email_address: user at domain.co.za
email_address: user at domain.co.za
oskar at core1:~$

Oskar



More information about the Za-pm mailing list