File: batch_replace.sh

package info (click to toggle)
simutrans 124.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,880 kB
  • sloc: cpp: 160,224; ansic: 9,382; sh: 1,237; awk: 1,081; makefile: 932; javascript: 2
file content (25 lines) | stat: -rwxr-xr-x 426 bytes parent folder | download | duplicates (2)
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
#/bin/bash
while IFS=, read from to
do
	echo "Replace $from by $to"
	REPLACE="s#$from#$to#g"

	find ../ -name "*.cc" -or -name "*.h" -or -name "Makefile"  -or -name "*.*proj" | while read fname; do

		sed "${REPLACE}" $fname > tmp.sed
		if [ $? -ne 0 ]; then
			break
		fi

		cmp -s tmp.sed $fname
		res=$?

		if [ $res -eq 1 ]
		then
			echo "Replace in $fname"
			mv tmp.sed $fname
		else
			rm tmp.sed
		fi
	done
done < $1