1

I am wondering why the following command wouldn't work:

sudo find . -name index.htm | xargs -0 sudo sed -i 's/pattern1/pattern2/g'

When ran the two commands separately, they worked as expected, find found all the files I was needing to change, and sed correctly replaced the text according to the regex (obviously when i ran the sed command separately i supplied a filename as an argument). When running them together with xargs -0, I got

sed:
    ./index.htm
    ./folder1/index.htm
    ./folder1/subfolder2/index.htm
    ...
    ...
    ./lastfolder/index.htm: No such file or directory

I ended up using

sudo find . -name index.htm -exec sudo sed -i 's/pattern1/pattern2/g' {} \;

and it worked fine, I was just curious why using xargs didn't work....

2 Answers2

3

You didn't use the -print0 option with find.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
1

Are there any spaces in the directory or file names?

mpez0
  • 1,512
  • 9
  • 9