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

Collapse
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: do-files.sh *.tcl or the like.

#!/bin/sh
# do-files.sh

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

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

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

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