#!/bin/sh
# Usage: tnotes <input> <text output> <notes output>
if fgrep "<corr" $1 > /dev/null; then
    echo "              Transcriber's Notes to the Electronic Edition" > $3
    echo "" >> $3
    echo "" >> $3
    sed -e 's/|/�/g' $1 | tr '\012' '|' | sed \
      -e 's/<corr//g' -e 's/<\/corr//g' -e 's/^[^]*//' \
      -e 's/\( was="[^"]*"\/>\)[^]*/\1/g' \
      -e "s/\( was='[^']*'\/>\)[^]*/\1/g" \
      -e 's/\( was="[^"]*">[^]*>\)[^]*/\1/g' \
      -e "s/\( was='[^']*'>[^]*>\)[^]*/\1/g" \
      -e 's/ was=\("[^"]*"\)\/>/    Removed \1.|/g' \
      -e "s/ was=\('[^']*'\)\/>/    Removed \1.|/g" \
      -e 's/ was="">\([^]*\)>/    Added "\1".|/g' \
      -e "s/ was=''>\([^]*\)>/    Added '\1'.|/g" \
      -e 's/ was=\("[^"]*"\)>\([^]*\)>/    Replaced \1 with "\2".|/g' \
      -e "s/ was=\('[^']*'\)>\([^]*\)>/    Replaced \1 with '\2'.|/g" \
      | tr '|' '\012' | sed 's/�/|/g' | sort -u >> $3
else
    echo -n '' > $3
fi
sed -e 's/<\/\?corr[^>]*>//g' $1 > $2
