find/grep command

Hi

Could someone help me with "find", "grep" or other idea, I have handrad files in different folders and I need to replace a word inside that files. e.g:

file name = test.txt
inside that test.txt a have a word "00001"

I want to replace the value "00001" to "00002".

thank you

find . -type f | while read file
do
sed 's/00001/00002/g' input.filename > tmp.filename
mv tmp.filename input.filename
done

To ensure the files being editted retain their ownership and permissions I would copy rather than move as follows:

find . -type f | while read file'; do
  sed 's/00001/00002/g' input.filename > tmp.filename && \
  cp tmp.filename input.filename && \
  rm tmp.filename
done

wouldn't it be easier to use 'mv'?
also what's the 'input.filename'?
and why do you need a trailing ' in "while read file' "?

Anyhoo...

find . -type f | while read file'; do
  printf '1,$s/00001/00002/g\n.\nwq!\n' | ex - "${file}"
done

You are correct, mentions of "input.filename" should be ${file}.

hi friends,

first of all thank you so much, i am testing yours tips...

To be specific in your case, I would just change one file which is the test.txt. Then use find to build up a list. Get rid off all of them and create symlinks instead, or even make copies. Just few lines based on the list 'find' built.

Well, as what I got from your description.

Did not answer two of your points:
Using mv means the permissions of the new file override the permissions of the original file, unlike a cp.

The trailing "'" will break things and was a typo!

In that case you'd probably need a 'cp -p'