File: replaceall

package info (click to toggle)
swi-prolog 7.2.3%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,180 kB
  • ctags: 45,684
  • sloc: ansic: 330,358; perl: 268,104; sh: 6,795; java: 4,904; makefile: 4,561; cpp: 4,153; ruby: 1,594; yacc: 843; xml: 82; sed: 12; sql: 6
file content (19 lines) | stat: -rwxr-xr-x 308 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash -f

from="$1"
to="$2"

if [ -z "$from" ]; then
   echo "Usage: $0 from to"
fi

files=`find . -name '*.[ch]' | xargs grep -l "$1"`
for f in $files; do
  cp -p $f $f.bak
  sed "s|$1|$2|g" $f.bak > $f
  if cmp -s $f.bak $f; then
    mv $f.bak $f	# no change
  else
    echo "	modified $f"
  fi
done