In Line File Modifications: Search and Replace

grep -il "TEST" ${ENVIRON}/*.pde| while read pde
��do
����cat $pde | sed s/"TEST 3,1"/"TEST 3,0"/g | sed s/"TEST��3,1"/"TEST��3,0"/g > ${pde}.tmp
����if [ -f ${pde}.tmp ] ; then
������mv ${pde}.tmp $pde
����else
������echo "Failure writing ${pde}.tmp"
����fi
��done

here is an example of my code doing a search and replace for the current directory, I was hoping to learn a little more, has anyone got a better solution?

I am concerned as this is dangerous code, however quick and simple to create.

It's good that this makes you nervous. A cautious attitude will spare you a lot a grief.

What makes the script that you posted dangerous is that it is going to rewrite many files, so you could lose a lot if it malfunctions. So don't do that. At the top, do...
mkdir garbage

and in your if statement do
mv $pde garbage
mv ${pde}.tmp $pde

After the script runs, you can examine the output files. If they look good, just do "rm -rf garbage". But if they look garbled, you still have those original in the garbage directory. I always use this approach when I write a script to modify many files. And several times a year, I am very glad that I did.

... and if you use PERL, there are command line switches to automatically create backup files of the originals ......