#!/bin/bash
cat spring2011-20101105.html | egrep '^(
.*$|Credits)' \
| sed 's/^.*crn_in=[0-9]\{5\}">\(.*\) - \([0-9]\{5\}\) - \([A-Z]\{3,4\} [0-9]\{4\}\) - \([0-9]\{3\}\)<\/A.*$/\2:\3-\4:\1/g' \
| sed 's/^ | \(.*\)<\/TD>$/\1/g' | sed 's/( output
mkdir -p courses
count=0
start=1
for item in `cat -n output | sed 's/^ *//g' | sed 's/\t/,/' | sed 's/ /*/g' \
| grep '^[0-9][0-9]*,[0-9][0-9][0-9][0-9][0-9]'`; do
if [ "$count" -eq 0 ]; then
count=1
olditem="$item"
continue
fi
end="`echo $item | cut -d',' -f1`"
crn="`echo $olditem | cut -d',' -f2 | cut -d':' -f1`"
let end=$end-1
# echo "start: $start"
# echo "end: $end"
let start=$start+1
let range=$end-$start
let range=$range+1
# echo "range: $range"
start=$end
olditem="$item"
cat output | head -n $end | tail -n $range > courses/$crn
done
exit 0