SPUG: Inspired, broken.

jlb jlb at io.com
Wed Feb 9 14:05:31 PST 2005

On Wed, 9 Feb 2005, Gardner Cohen wrote:
> sudo /bin/sh -c "yourcommand > yourfile.txt"
> which will make the redirection happen in a shell running as root.

Right, I was trying to avoid figuring out how to quote this properly 
because I hate messing with quotes but something like this is probably 

sudo /bin/bash -c 'perl -wnl -e "m/\w+\@\w+\.\w{3}/ and print
   lc($&).q{ OK}" addresses.txt > outfile.txt'

Although from the looks of your code, I think may be expecting that to 
potentially match more than one address per line, which it actually 
doesn't.  If there is the possibility of two addresses being on one line, 
you'd want something like this.

sudo /bin/bash -c 'perl -wnl -e "print lc($&).q{ OK}
   while m/\w+\@\w+\.\w{3}/g" addresses.txt > outfile.txt'

I looked, but I didn't see a command line parameter to instruct perl to 
redirect stdout by default, to avoid all the /bin/bash nonsense.  Anyone 
know of anything like that appropriate for one liners?

The only thing close was -i, which isn't really waht you want.

More information about the spug-list mailing list