SPUG: Inspired, broken.

John W. Krahn krahnj at telus.net
Wed Feb 9 17:23:48 PST 2005

Tim Maher wrote:
> On Wed, Feb 09, 2005 at 12:52:47PM -0800, Atom Powers wrote:
>>Inspired by last night's presentation at the Seattle Unix Group I put 
> Glad to hear that! 8-}
>>together this perl one-liner to grab email addresses out of a file.
>>It works, but I need to save the output to a file, "recipients.txt", and 
>>I'm having trouble.
>>What is the best way to save the output to a file?
>>#perl5 -wnl -e 'm/\w+@\w+\.\w{3}/ and print lc($&)." OK";' address_list.txt
>>I've tried this:
>>>perl5 -wnl -e 'm/\w+@\w+\.\w{3}/ and print lc($&)." OK";' address_list.txt > recipients.txt
>>recipients.txt: Permission denied.
> That format /will/ work, assuming you're in a directory for which
> you have write permission when you issue the command.
> As a general rule, you should backslash the @ within the matching
> operator's // delimiters, because it will in some cases be taken
> for the start of an array name otherwise.  And double-quotes make
> string construction easier:

Of course it won't work if there are any \W characters in the user name or if 
the TLD isn't exactly three characters.  This may work better:

perl5 -nl -e'print"\L$_\E OK"for/(\S+\@[\w.-]+\.\w{2,})\b/g' address_list.txt 
 > recipients.txt

use Perl;

More information about the spug-list mailing list