sed: can't read : No such file or directory
Asked Answered
E

1

7

I am running the following command:

find . -name '*.html' -exec sed "s/foo/bar/g" {} \;

where the file structure looks like this:

./two/three.html
./two/two.html
./two/one.html
./three/three.html
./three/two.html
./three/one.html
./one/three.html
./one/two.html
./one/one.html

However, sed comes back saying the files could not be found, even though these two commands work fine on their own (i.e. I can run a find by itself, and I can run sed by itself fine).

I had a peer look at it with me, and he was stumped also. I ended up going a different route, but I'd still like to know what exactly is going wrong here.

Enterotomy answered 28/3, 2014 at 14:52 Comment(6)
What if you remove the -print part? To me it looks unnecessary.Inguinal
print will print the name of the file before sed does the action. Probably something that OP wants.Prisage
assuming you're really using sed -i to "save In-place", else where is the output going in your example. I think @Inguinal is onto something. Good luck.Gahan
I added -print to make sure it was hitting the files. When I remove it, I get the same results.Enterotomy
Possibly the unquoted braces are a problem. Try: -exec sed 's/foo/bar/g' '{}' \;Cockleshell
To wrap up the question, you might as well post an answer, so others can benefitCockleshell
E
4

Thanks to glenn jackman for the advice:

I needed to place quotes around the brackets as such:

-exec sed "s/foo/bar/g" '{}' \;

Rather than how I initially posted it.

Enterotomy answered 31/3, 2014 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.