Using ed to manipulate files matched by find

Posted by TheOsp on Stack Overflow See other posts from Stack Overflow or by TheOsp
Published on 2010-05-10T23:32:57Z Indexed on 2010/05/10 23:44 UTC
Read the original article Hit count: 417

Filed under:
|
|
|

Following the bash-hackers wiki's recommendation, I want to edit files using ed.

In particular I want to do the following with ed instead of sed:

find . -type f -exec sed -i -e 's/a/b/g' {} \;

I see that ed doesn't have opt like sed's -e, so as far as I know, pipes and io redirections are the only way to work with it non-interactively.

So, using ed from a bash script to do the same as the above sed command would look like:

ed file_name <<<$'g/a/s//b/g\nw'

Or

echo $'g/a/s//b/g\nw' | ed file_name

But as far as I know it is impossible to involve pipes or io redirections within find's -exec.

Do I miss something? or is the only way to overcome this is to use loops?

for file in $(find . -type f -print); do ed $file <<<$'g/a/s//b/g\nw'; done;

© Stack Overflow or respective owner

Related posts about bash

Related posts about ed