[NTLUG:Discuss] sed script

terry trryhend at gmail.com
Tue Jan 27 14:37:06 CST 2009


I found and adapted a script to do a particular job, (to change one
word in multiple files).
Here is the script:
================
find . -type f | while read file
do
sed 's/oldword/newword/g' $file >$file.$$
mv $file.$$ >$file
done
================
and I end up with all  the newly revised files having .#### extensions.
So to get rid of the .##### extensions and delete old files, I used command:
  rename  .html.12422  .html   *.html.12422

Part of the script worked as I expected, part of it didn't, [probably
very clumsy], BUT.. I ended up getting the job done ok
Just wondering
1)  How to correct this script to make it work better / more
efficiently for further use, (do the clean-up job for me).
    and / or
2)  What change would I make if I only wanted to do it to one
directory, (not recursively)?  (I suppose I could mkdir temp/ ;cp
*.html  temp/   and then  mv temp/* . ; rmdir temp/  afterward, but,
you see, I would only want to do it to the html files and only to that
one directory)

Answer #2 is not all that important, but would just like to learn to
make it just a little more convenient if possible.
--
<><



More information about the Discuss mailing list