[NTLUG:Discuss] sed script
Eric Waguespack
ewaguespack at gmail.com
Tue Jan 27 14:42:27 CST 2009
man sed
...
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
...
find . -type f -exec sed -i 's=old=new=g' {} \;
man find
...
-maxdepth levels
Descend at most levels (a non-negative integer)
levels of directories below the command line arguments. â-maxdepth 0â
means
only apply the tests and actions to the command line arguments.
...
-Eric
On Tue, Jan 27, 2009 at 2:37 PM, terry <trryhend at gmail.com> wrote:
> 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.
> --
> <><
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list