Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.