User Tools

Site Tools


haas:spring2011:unix:eoce:scripts


Corning Community College


UNIX/Linux Fundamentals



EoCE Scripts

~~TOC~~

Script 0: Variant of in-class Example

1
#!/bin/bash                                                                               
 
cat spring2011-20101105.html | egrep '^(<TH CLASS="ddtitle"|<TD CLASS="dddefault">.*</TD>$|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.*ault">\(.*\)<\/TD>$/\1/g' | sed 's/(<ABB.*$//g' | sed 's/^.*TBA.*$/TBA/g' \
| sed 's/^&nbsp;$/NA/g' | sed 's/^ *//g' > 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

This script based on the approach taken by the in-class example

Script 1: Alternate Approach

1
#!/bin/bash
 
file1="spring2011-20101105.html"
file2="spring2011output.txt"
file3="spring2011output2.txt"
 
cat $file1 | egrep '^(<TH CLASS="ddtitle"|<TD CLASS="dddefault">.*</TD>$|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.*ault">\(.*\)<\/TD>$/\1/g' | sed 's/(<ABB.*$//g' | sed 's/^.*TBA.*$/TBA/g' \
| sed 's/^&nbsp;$/NA/g' | sed 's/^ *//g' > $file2
 
cat -n $file2 | sed 's/^ *//g' | sed 's/\t/,/' | sed 's/ /*/g' \
| grep '^[0-9][0-9]*,[0-9]{5}' | sed 's/,/:/' > $file3
 
filecontent=( `cat $file3 `)
for t in "${filecontent[@]}"; do
    line=$(echo $t | cut -d":" -f1)
    crn=$(echo $t | cut -d":" -f2)
    classcode=$(echo $t | cut -d":" -f3)
    description=$(echo $t | cut -d":" -f4)
    echo -e "$crn\n$classcode\n$description" > "classlists/$crn.txt"
done
 
echo "Enter a CRN to look up."
read crnlookup
clear
cat classlists/$crnlookup.txt | sed 's/*/ /g'
 
answer=true
while ($answer -eq true); do
    echo ""
    echo "Do you want to look up another CRN y/n?"
    read answers
    clear
    if [ $answers = 'y' ]; then
        answer=true
        echo "Enter a CRN to look up."
        read crnlookup
        cat classlists/$crnlookup.txt
    else
        answer=false
    fi
done
 
exit 0

This script based on the approach taken by Bradley Owlett

haas/spring2011/unix/eoce/scripts.txt · Last modified: 2010/12/02 00:13 by 127.0.0.1