#!/bin/bash
if [[ "$1" == "-v" ]]
then
course=$2
action() {
tr '\r' '\n' | grep '
\|' | sed -e 's/<[^>]\+>//g' | grep -Ei "^${course}J? " -A 1000 | perl -pe 'exit unless /^\s+/ || $.==1' | sed -e 's/^\s\+//g'
}
else
course=$1
action() {
sed -n 's/^
//p' | grep -Ei "^${course}J? ";
}
fi
major="$(echo "$course" | sed 's/\..*//' | tr a-z A-Z)"
for i in a b c; do
wget -q -O- http://student.mit.edu/catalog/m"${major}${i}".html
done | action