Global replace with sed

Hi,

I need to change some strings from A to B in a number of files within a directory. Please can someone advise how do I do that?

Many thanks

Read this page and when you finish get back to us.

Thanks, however it will be nice if you can just put the command here. I m doing something like

find . -name "*.txt*" -type f -exec sed -e 's/ugly/bad/g' {} \;

but it doesn't like it.

Thnx

"It doesn't like" is not very specific, do you get an error message or surprising results or nothing at all?

You are not saving the output from sed anywhere so my guess would be you would see the files roll across your screen with the substitutions made as requested. If your sed supports the -i option then you can use that. Otherwise a simple temporary external script is probably the way to go.

I am on solaris 8 and getting illegal option error. Looks like I am using a sed which does not support sed -i :frowning:

Thanks guys for your help!

Use a temp file.

 find . -name "*.txt" -type f -exec sed 's/ugly/bad/g' {} > tmp \; -exec mv tmp {} \;