Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
grep -r -l --include=*.{html,js,css} "\bAA\b" . | xargs -0 -n 1 sed -i -e "s/\bAA\b/BB/g"

When I ran the above command, I got the following error:

sed: can't read ./login.html : No such file or directory

This is rather odd as I am able to vi ./login.html

I don't understand why am I getting this error. Please help. Thanks.

share|improve this question
up vote 1 down vote accepted

You shouldn't be using -0 with xargs unless the previous command actually uses NUL to delimit its output, which grep does not unless you use -Z. Therefore it's looking for "./login.html " and not "./login.html" (note the space).

share|improve this answer
    
Thanks. Dropping -0 works! But I am curious is it a more flexible way to use the -z approach (so that I can match newline character in my regular expression)? – tamakisquare Nov 15 '11 at 2:26
1  
Correct. Without it, xargs will consider a newline in a filename to be an argument separator instead. – Ignacio Vazquez-Abrams Nov 15 '11 at 2:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .