Not long after I posted the original autograding script, I figured out a way to colorize the output. My solution was html. Here’s the script in it’s final (for now) form.
EDIT – For some reason, WordPress really doesn’t like this script, even within the pre tags. If you want to use it, you’ll just have to do a search and replace to get rid of the < and > to replace them with the appropriate characters.
#!/bin/bash
WORKDIR=$1
KEYFILE=$2
GRADEDDIR=$WORKDIR/graded
# first check if there are two arguments:
if [ "$#" -ne 2 ]; then
echo "usage: $0 </path/to/files> </path/to/answerkey.txt>"
exit
fi
#checks to see if $GRADEDDIR exists and creates it if it does not
if [ ! -d "$GRADEDDIR" ]; then
mkdir -p "$GRADEDDIR"
fi
#converts MS Word format to plain text
for UNGRADED in $WORKDIR/*.docx; do
docx2txt.sh $UNGRADED;
done
#compares text files against key and outputs to .GRADED.txt file
for GRADED in $WORKDIR/*.txt; do
dwdiff -s $KEYFILE $GRADED > "$WORKDIR/$(basename $GRADED .txt).GRADED"
done
#renames .GRADED file with information dwdiff writes to end of file
for RENAMED in $WORKDIR/*.GRADED; do
mv $RENAMED "$WORKDIR/$(basename $RENAMED .GRADED).$(grep "old:" $RENAMED).RENAMED"
done
#moves graded files to graded directory
for MOVED in $WORKDIR/*.RENAMED; do
mv "$MOVED" $GRADEDDIR/
done
#begin converting .RENAMED to .html
for COLORIZED in $GRADEDDIR/*.RENAMED; do
cat "$COLORIZED" | sed -e 's/\[-/<span style=\"background-color:red\">/g' -e 's/-\]/<\/span>/g' -e 's/{+/<span style=\"background-color:yellow\">/g' -e 's/+}/<\/span>/g' -e '1i<html>\n<body>\n<pre>' -e 's/old:/Answer Key:/' -e 's/new:/Your Document:/' > "$COLORIZED.html"
done
#finish converting .txt to .html
for HTMLEND in $GRADEDDIR/*.html; do
echo "</pre>
</body>
</html>" >> '$HTMLEND'
done
#clean up the filenames a bit
rename 's/.old: /\-/' $GRADEDDIR/*.html
rename 's/.RENAMED././' $GRADEDDIR/*.html
#removes .txt files from $WORKDIR and .RENAMED files from $GRADEDDIR
rm $WORKDIR/*.txt
rm $GRADEDDIR/*.RENAMED
