Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Mladen Gogala Newsgroups: comp.os.linux.misc Subject: Re: Script to parse a text file and extract unique email addresses Date: Mon, 29 Sep 2014 00:17:34 +0000 (UTC) Organization: solani.org Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1411949854 17300 eJwFwQcBADAIAzBLO1w5HVD/EpbotW3lYmqiVGJdBiDp0t6beIF5jc4KjzmH06jOoz6+hh892RKO (29 Sep 2014 00:17:34 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 29 Sep 2014 00:17:34 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) X-User-ID: eJwVx8ERwDAIA7CVKNgOjNPQsP8Iueonhh71gihwOFNv7ozAaRGNv55WTq/9Dap9EjKlnViyCxWaEFs= Cancel-Lock: sha1:kcYlhXmu769b2P6r45n2HcIOxtg= X-NNTP-Posting-Host: eJwFwYEBgDAIA7CXZNCC50wo/59gAqexMwgGFpvWrW8aHHF8YRcP7a4UddLrlMpkg2h/M34xjxE7 Xref: csiph.com comp.os.linux.misc:12180 On Tue, 19 Aug 2014 10:19:24 -0700, nomdeplume82008 wrote: > Hi all, > > My scripting is a v. rusty and I am trying to write a script that will extract unique email addresses from an out Outlook file to build an address book. > > In the output file, all the email addresses should preferably be in a single alphabetical column. > > Any suggestions on how to do it? > > Thanks. Here is my take: #!/usr/bin/env perl use warnings; use strict; my %EMAILS; while (<>) { if (/([a-z0-9.-]+\@[a-z0-9.-]+)/i) { if ( !defined( $EMAILS{$1} ) ) { $EMAILS{$1} = 1; } else { next; } } else { next; } } foreach my $addr ( sort keys %EMAILS ) { print "$addr\n"; } -- Mladen Gogala The Oracle Whisperer http://mgogala.byethost5.com