#!/bin/sh # replace - UNIX shell script for text replacement over several files # using sed. # George Ruban gruban@geocities.com 2/5/97 # http://www.geocities.com/SiliconValley/Vista/2013 # GR 3/6/97 - added from/to parameter slash escaping # check command line arguments if [ "$#" -lt 3 ] then echo "Usage: replace from to files..." exit 1 fi # get from and to parameters # escape any slashes in the parameters with backslashes from=`echo "$1" | sed 's/\//\\\\\//g'` to=`echo "$2" | sed 's/\//\\\\\//g'` # prepare file names for looping over shift 2 # do the work: loop over supplied command line files for file do # try the replacement to a temporary file echo "replacing '$from' with '$to' in $file..." tempname=/tmp/`basename $file`.$$ if sed "s/$from/$to/g" "$file" > "$tempname" # if it succeeded, replace the original then mv "$tempname" "$file" fi done