Using grep and xargs, avoiding the "unterminated quote" error

I am so upset that I decided it was time to ask a question.

I am trying to replace an email address on a website that is hardcoded to 1000 pages. This is on a FreeBSD 6.3 server.

Here is the command I'm 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 I keep getting:

xargs: unterminated quote

Oddly enough, when I run this command in a test case of 3 files (in a nested structure) it works fine. I work at Google and most of the solutions seem to involve adding -print0 after. and -0 after xargs. However, this gives a different set of errors that lead me to believe that I am putting things in the wrong places.

in advance for your help

+1


a source to share


3 answers


Pax is correct. I would still fix 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 complete FreeBSD:



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

      

Please note that I have removed sort and uniq. --files-without-match is documented to "stop the first match" so you don't get duplicate files. -print0 and -0 provide (and process) a null-terminated list of files, which is very important because POSIX allows file names to contain newlines.

Note that I don't know perl, but I assume this part is roughly equivalent:

sed -i s/Email\@domain.com/Email\@newdomain.com/g

      

+2


a source


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



+1


a source


Using the GNU Parallel Interface:

grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | parallel -q perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/g'

      

Watch the video for more information: http://www.youtube.com/watch?v=OpaiGYxkSuQ

0


a source







All Articles