#!/bin/csh -f

# Edit files after first two arguments to replace argument 1 with argument two
# Also cleanup '#!" occurences to not have a following space.
# Good for standardizing scripts and taking care of situations where a shell
# is in a different location than before, e.g., when moving to a new system.

set oldpath = "$1"
set newpath = "$2"
shift
shift

foreach file ($*)
  if (-f $file) then
    mv $file $file.old
    sed "s+$oldpath+$newpath+\
         s+#\! *+#\!+" $file.old > $file
    chmod +x $file
    touch -r $file.old $file
    rm $file.old
  endif
end
