Wednesday, August 17, 2005

Once I wrote a global search and replace ...

... and now I find that a simple bit of unix command line replaces hundreds of lines of MoonRock BASIC.

$ for x in *.chk; do cat $x | sed -e s/Database=/Filename=/ > tmp; mv tmp $x; done

Get every file ending in .chk, pipe it through sed to change the relevant string, capture the result into a temporary file and then copy it over the original.

1 comment:

rms_s4 said...

> for x in *.chk; do cat $x | sed -e s/Database=/Filename=/ > tmp; mv tmp $x; done

At least with the GNU sed you can skip the move step (using inplace editing).
The original file content will be stored in .bak file:

for x in *.chk
do
sed \
-i.bak \
-e 's+Database=+Filename=+g' $x
done