Using ed to manage files matching search

Following the bash -hakers wiki 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 a choice of sed -e, as far as I know, feeds and forwarding are the only way to work with it non-interactively.

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

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 not possible to use pipes or io redirects in find -exec.

Did 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;
+3
source share
3
find . -type f -exec bash -c 'ed -s "$2" <<< "$1"' _ $'g/a/s//b/g\nw' {} \;

POSIX:

find . -type f -exec sh -c 'printf "%s\n" "g/a/s//b/g" w | ed -s "$1"' _ {} \;

ed sed -i , ed , sed -i , , , .

+4

find ed snippet ( , acutal):

find ed

http://codesnippets.joyent.com/posts/show/2299

+1

ed " " script find.

: ? , ed, sed?

0

Source: https://habr.com/ru/post/1744855/


All Articles