tags:

views:

1707

answers:

2

Hi,

I'm getting frustrated enough that I figured it was time to ask a question.

I'm trying to replace an email address across a website that is hard coded into 1000's of pages. It's on a FreeBSD 6.3 server.

Here is the command I am using:

grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | xargs perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/' *.html

And here is the error that I keep getting:

xargs: unterminated quote

Oddly enough, when I run that command on a test case of 3 files (in a nested structure) it works just fine. I've been googling and most solutions seem to deal with adding a -print0 after the . and a -0 after the xargs. However, this yields a different set of errors that lead me to believe I'm putting things in the wrong places.

thanks in advance for your help

+1  A: 

Why are you giving a list of HTML files to xargs? That program takes its file list from the pipeline (output of grep).

paxdiablo
+1  A: 

Pax is correct. I would further correct it to something like:

grep -R --files-with-matches 'Email\@domain.com' . -print0 | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

EDIT:

Thanks to kcwu, this is the full FreeBSD:

grep -R --files-with-matches 'Email\@domain.com' . --null | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

Note that I've removed sort and uniq. --files-without-match is documented to "stop on the first match" so you will not get duplicate files. -print0 and -0 ensure (and handle) a null-terminated file list, which is vital, because POSIX allows filenames to contain newlines.

Note that I don't know perl, but I'm assuming that part's roughly equivalent to:

sed -i s/Email\@domain.com/Email\@newdomain.com/g
Matthew Flaschen
Thanks for the quick reply. When I try to add the -print0, I get the following:jhmail# grep -R --files-with-matches 'FineArt\@westliveson.com' . -print0 | xargs -0 perl -pi -e 's/FineArt\@westliveson.com/FA\@westliveson.com/'grep: invalid option -- pUsage: grep [OPTION]... PATTERN [FILE]...Try `grep --help' for more information.
On FreeBSD, use "--null" instead of "-print0"
kcwu
Perfect! Thank you guys so much for your help. Much appreciated.