On Wed, 2002-12-11 at 10:55, Robin Ballantine wrote:
> On Tuesday 10 December 2002 4:23 pm, Brian York wrote:
> > I have some log files that have a bunch of crap in them. I need to extract
> > all of the email addresses in them and put them in a file.  Does anyone
> > know how I might be able to do this?
> > Find       > emails.file
> > Thanks
> > Brian
> 
> If your logfile is a normal text file and your mail addresses are between 
> angle brackets, you could use grep on it to extract the lines containing them 
> and then pipe the output through sed to remove the chaff either side and then 
> finally through sort and uniq. eg;
> 
> grep "<.*@.*>" your-logfile | sed 's/^.*</</; \
>                                  s/?.*>/>/;   \
>                                  s/mailto://; \
>                                  s/>.*$/>/' | sort | uniq > emails.file
> 
> <snip>

Or the perl way:

grep "@" log | perl -e 'while (<>) { m/.*<(.*@.*)>.*/; print $1,"\n";}'

The grep is just being lazy to only pass lines containing email
addresses to the perl script. The print $1 prints the result of the
captured bit of text in the ()

If your comfortable with regex's you can do a fair bit of stuff with
variations on the theme (
http://www.bennee.com/~alex/wiki/index.php/One%20Line%20Scripts)


-- 
Alex Bennee
Senior Hacker, Braddahead Ltd
The above is probably my personal opinion and may not be that of my
employer


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to