I’m now teaching a section of sixth grade technology class. In a nutshelll – it’s typing. Not to demean that – I believe good typing skills are essential. They certainly have served me well.
I’m using moodle to collect everything from my students, because I can’t stand using paper – I’ll lose it faster than you can imagine. Still, that left me with the unpleasant task of grading these files. Essentially, I end up with about 20 files that should be exactly identical to the key. At first, I thought I would use Word’s built in compare documents feature. While this certainly would be better than grading by hand, it was tedious and the results were still difficult to translate into a reasonable grade.
After being recently introduced to the for loop, I figured that a bash script had to be the answer. I wrote this script last night and revised it throughout the day today. I learned how to pass arguments from the command line thanks to help from my brother. He also helped me clean up the code a bit, for which I’m grateful.
For this script to work, you need to have docx2txt installed as well as dwdiff. if you’re on ubuntu, it’s just a simple “sudo apt-get install” and you’re on your way.
autograde /path/to/files/to/be/graded /path/to/answerkey.txt
This will output files with a percentage common, inserted, and deleted all in the filename. Yeah, it makes a huge filename, but I like having all that info right there.
Feel free to modify it for your own needs or make suggestions on how I can improve it. For what it’s worth, the usage statement is correct in the actual script, but somehow I can’t get the arguments to display in wordpress.
#!/bin/bash WORKDIR=$1 KEYFILE=$2 GRADEDDIR=$WORKDIR/graded/ # first check if there are two arguments: if [ "$#" -ne 2 ]; then echo "usage: $0 " 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 > $GRADED.GRADED.txt done #renames .GRADED.txt file with information dwdiff writes to end of file for RENAMED in $WORKDIR/*.GRADED.txt; do mv $RENAMED "$RENAMED.$(grep "old:" $RENAMED).txt" done #moves graded files to graded directory for MOVED in $WORKDIR/*old:*.txt; do mv "$MOVED" $GRADEDDIR done #removes ungraded.txt files from $WORKDIR rm $WORKDIR/*.txt
I’m really enjoying learning how to script. This one will save me many hours of valuable time. The next thing I want to do is to have the script echo the proper usage when entered without arguments. That’s probably just a few google searches away, but that’s for another day. (done). Next I want to see if there’s a way I can save the color output. I can do output in color using “dwdiff -c” within the script, but I need to figure out if there’s a way that I can save that color coding into a file format that retains the color information so I can give it to students as feedback. Thus far, I have only succeeded at seeing the color within the terminal window.