view hammond/translate.sh @ 15:853caf8cd74b

Update
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 04 May 2016 17:25:19 +0100
parents d2eb0e6ccaaf
children
line wrap: on
line source
#!/opt/local/bin/bash


SOURCE="$1"
TRANSLATOR="$2"
NUM_LINES=`cat $TRANSLATOR | wc -l` #using cat to avoid filename being output by wc
OUTPUT_PREFIX=`sed "1q;d" $TRANSLATOR` #first line should include folder prefix to the output file
OUTPUT_FILE="${OUTPUT_PREFIX}${1}"

i=2
SOURCE_CONTENT=`cat $1`

while [ $i -le $NUM_LINES ];
do
  searchfor=`sed "${i}q;d" $TRANSLATOR` 
  i=$(($i+1))
  replace=`sed "${i}q;d" $TRANSLATOR` 
  replace=$(echo $replace | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')
  SOURCE_CONTENT=`printf "$SOURCE_CONTENT" | sed -e "s/$searchfor/$replace/g"`
  i=$(($i+1))
done;
echo "$SOURCE_CONTENT" > $OUTPUT_FILE