#!/usr/bin/sh
if [ "`uname`" = "Linux" ]; then enable -n echo; fi
##*************************************
##
## E.S.O. - VLT project
##
## "@(#) $Id: tooReplace,v 1.45 2004/11/16 13:36:49 vltsccm Exp $"
##
## tooReplace"
## 
## who     when        what
##-------- ----------  ------------------
##mchiesa  02/21/95    created for cmm
##eallaert 2004-11-16  added CAUTIONS section to manpage - SPR 20040098
##


#************************************************************************
#   NAME
#   tooReplace - replace strings in files
# 
#   SYNOPSIS
#   tooReplace str1 str2 files ...
#
#   DESCRIPTION
#   tooReplace replaces str1 with str2 in given files.
#
#   CAUTIONS
#   This script will pipe stdout over 'sed' to stdin, meaning that it will
#   finish on the EOF (<ctrl>D) for stdout/stdin. Hence for files containing 
#   binary data this can result in truncated files. Ensure that the list of
#   files to process excludes binary files, or use tooReplace2 with the
#   '-nobinary' option instead.
#
#   SEE ALSO
#   tooReplace2(1)
#------------------------------------------------------------------------

# tooReplace: tooReplace str1 in files with str2, in place
# The UNIX Programming Environment, Brian W. Kernighan & Rob Pike
#    Prentice-Hall, Englewood Cliffs 1984, page 155



localpath=`dirname $0`
PATH=/bin:/usr/bin:$localpath

case $# in
0|1|2) echo $0' (Usage): tooReplace str1 str2 files' 1>&2; exit 1
esac

left="$1"; right="$2"; shift; shift

for i 
do 
	tooOverwrite $i sed "s@$left@$right@g" $i
done
