Forum OpenACS Q&A: Response to little problem with nsd8x

Posted by Andrew Piskorski on
David, someone has probably written a perl script to do just that.

But, I've done a lot more shell hacking than Perl. I've never needed to traverse a whole directory trees, but here's a really simple bourne shell script to replace "foo" with "bar" and "xx" with "yy", for files in a single directory only. It just dumps the new versions of the files into the tmp/ subdir. You'd run it with: *.tcl or the like.


mkdir tmp
for x
  cat $x | sed -e 's%foo%bar%g' | 's%xx%yy%g' > tmp/$x
Hm, you could probably cobble together something ugly like:
find /web/mydir -name "*.tcl" -exec {} ;
where is:

set dir_tree `dirname $1`
set tmp_tree "/tmp${dir_tree}"

if [ ! -r $tmp_tree ] ; then
  mkdir -p $tmp_tree

cat $x | sed -e 's%foo%bar%g' | 's%xx%yy%g' > $tmp_tree/$x
Of course, I haven't tested that at all.