Rev | Line | |
---|
[65] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | #$Id: replid,v 1.2 1999/11/06 21:23:19 bittner Exp $ |
---|
| 4 | # Initially coding Jiri Bittner |
---|
| 5 | |
---|
| 6 | if [ $# -lt 3 ]; then echo "Usage: replid strA strB file_list $1 $2"; fi |
---|
| 7 | |
---|
| 8 | STR1=$1 |
---|
| 9 | STR2=$2 |
---|
| 10 | |
---|
| 11 | shift |
---|
| 12 | shift |
---|
| 13 | FILES=`grep -l $STR1 $*` |
---|
| 14 | |
---|
| 15 | echo $FILES |
---|
| 16 | |
---|
| 17 | SEPARATORS='[^a-zA-Z0-9_\.]' |
---|
| 18 | BACKUPDIR="Backup" |
---|
| 19 | |
---|
| 20 | if [ ! -d $BACKUPDIR ]; then mkdir $BACKUPDIR; fi |
---|
| 21 | |
---|
| 22 | for FILE in $FILES; do |
---|
| 23 | echo "Replacing in $FILE" |
---|
| 24 | cp $FILE $BACKUPDIR/$FILE |
---|
| 25 | CMD='-e s/\('$SEPARATORS'\)'$STR1'\('$SEPARATORS'\)/\1'$STR2'\2/g -e s/^'$STR1'\('$SEPARATORS'\)/'$STR2'\1/g -e s/\('$SEPARATORS'\)'$STR1'$/\1'$STR2'/g -e s/^'$STR1'$/'$STR2'/g' |
---|
| 26 | # echo $CMD |
---|
| 27 | sed $CMD < $BACKUPDIR/$FILE > $FILE.tmp |
---|
| 28 | mv $FILE.tmp $FILE |
---|
| 29 | done |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
Note: See
TracBrowser
for help on using the repository browser.