Bugfix: Adjustments for Mac OS X 10.11 (El Capitan). Author: Martin Beaudoin. Merge...
[foam-extend-3.2.git] / bin / tools / inlineReplace
blob310787935a7aa856eb71508b4e74a2f2581a4a0a
1 #!/bin/sh
3 # $0 string1 string2 file1 .. filen
5 if [ $# -lt 3 ]; then
6 echo "Usage: `basename $0` [-f] <string1> <string2> <file1> .. <filen>"
7 echo ""
8 echo "Replaces all occurrences of string1 by string2 in files."
9 echo "(replacement of sed -i on those systems that don't support it)"
10 exit 1
13 FROMSTRING=$1
14 shift
15 TOSTRING=$1
16 shift
18 for f in $*
20 if grep "$FROMSTRING" "$f" >/dev/null
21 then
22 cp "$f" "${f}_bak"
23 sed -e "s@$FROMSTRING@$TOSTRING@g" "${f}"_bak > "$f"
24 rm -f "${f}"_bak
25 #else
26 # echo "String $FROMSTRING not present in $f"
27 #fi
28 done