1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#! /bin/tcsh
# USAGE:
# subst [-b] <sed substitution expression> <file names>
#
# FUNCTION
# The sed substitution expression is applied globally to every file.
# The format of this expression is
# /regular expression/replacement string/
# For more information see sed(1).
# If option "-b" is set, the original files are renamed with the
# extension ".bak", otherwise the original files are replaced.
if ("$1" == "-b") then
set backup
set sedexp="$2"
set names=3
else
unset backup
set sedexp="$1"
set names=2
endif
if ($#argv < $names) then
echo "USAGE:"
echo " subst [-b] <sed substitution expression> <file names>"
exit
endif
foreach i ($argv[$names-])
mv $i $i.bak
sed -e "s${sedexp}g" $i.bak > $i
if (! $?backup) rm $i.bak
end
|