-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.sh
executable file
·36 lines (27 loc) · 917 Bytes
/
execute.sh
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
34
35
36
#!/bin/bash
# required for correct sed work
export LC_CTYPE=C LANG=C
replace_occurrences() {
INPUT_FILENAME=$1
REPLACED_STRING=$2
REPLACING_STRING=$3
echo "Input file ${INPUT_FILENAME}: replace ${REPLACED_STRING} with ${REPLACING_STRING}"
if [ -z "$INPUT_FILENAME" ] ; then
echo "Empty INPUT_FILENAME"
exit 0
fi
if [ -z "$REPLACED_STRING" ] ; then
echo "Empty REPLACED_STRING"
exit 0
fi
if [ -z "$REPLACING_STRING" ] ; then
echo "Empty REPLACING_STRING"
exit 0
fi
if [[ "$REPLACED_STRING" == "$REPLACING_STRING" ]] ; then
exit 0
fi
OUTPUT_FILENAME=$(echo $INPUT_FILENAME | sed "s/${REPLACED_STRING}/${REPLACING_STRING}/g")
cat $INPUT_FILENAME | sed "s/${REPLACED_STRING}/${REPLACING_STRING}/g" > $OUTPUT_FILENAME
}
#replace_occurrences <#SourceFile.swift#> <#ReplacedString#> <#ReplacingString#>