#!/bin/csh
# kswaps: global substitution of two strings for a set of files
# syntax: kswaps string1 string2 filenames
#

switch ($#argv)
	case '0':
	case '1':
	case '2':
		echo 'kswaps: Too few arguments!'
		echo 'Usage: kswaps string1 string2 filenames'
		exit -1
		breaksw
	default:
		breaksw
endsw

set host = `hostname`
set files = `ls $argv[3-]`
set tmpfile = /tmp/${host}.$$.kswap

foreach file ($files)
	echo Swapping $1  $2 for $file...
	sed -e "s/$1/$2/g" $file > $tmpfile
	mv -f $tmpfile $file
end
echo Done.
