======Project: Course aterial manipulation====== A project for Systems Programming by Brandon Kennedy during the Fall 2011 Semester. This project was begun on Nov. 5th and is anticipated to 1 week. =====Objectives===== The purpose of this project is to refresh myself on regex commands and unix shell scripting. =====Prerequisites===== In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved: * CSCS 1730 Unix/Linux Fundamentals * understanding of unix file access, permissions, directories and regex from CSCS 1730 =====Background===== The idea behind this project is to reflect on regex commands and shell scripting from CSCS 1730 in an attempt to retain as much as possible form a previous class. The script used in the project will accept command line arguments that are file names. If no arguments are specified the script will access a set directory to retrieve a set file of course data. This program will change the file permissions reguardless of what they are set at, cat the contents, manipulate them, and set the permissions by chmod 600 [filename]. =====Scope===== The focus of this project is to manipulate course catalog data. =====Attributes===== State and justify the attributes you'd like to receive upon successful approval and completion of this project. * File I/0: This script will read a file and manipulate its data * Command-line arguments: This script will accept command line arguments and manipulate them * pipes: This script will use pipes * directories: This script will access a directory * file attributes: This script will use chmod to edit file permissions. * I/0 Redirection: The script will output to a file. =====Procedure===== I took a script i had written in CSCS 1730 that manipulated course catalog data and added a little functionality to it. I had to do a little research to remember how to use for loops and the echo command, but it was a pretty straight forward project. I created a directory and added the spring2011-20101105.html file to it so that my script could default to that directory if no command line arguments were given. =====Code===== #!/bin/bash -x if [ $# -eq 0 ] then echo "No arguments entered, changing to semesterfiles/ to get data" for i in 1 2 3 4 5 6 7 8 do echo -n " /" sleep .1 echo -n "\b\b" echo -n " -" sleep .1 echo -n "\b\b" echo -n " \\" sleep .1 echo -n "\b\b" echo -n " |" sleep .1 echo -n "\b\b" done cd semesterfiles chmod 660 spring2011-20101105.html touch file1 cat spring2011-20101105.html | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l > touch1 chmod 600 spring2011-20101105.html else if [ $# -eq 1 ] then echo "the first argument is $1" cat $1 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l else if [ $# -eq 2 ] then vam=$(echo $1 | sed 's/-2.*html//g') vat=$(echo $2 | sed 's/-2.*html//g') if [ "$vam" = "$vat" ] then echo "argument 1 is $1" cat $1 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l echo "argument 2 is $2" cat $2 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l else echo "argument 1 is $1" cat $1 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l echo "English classes offered:" cat $1 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'ENGL' | wc -l echo "argument 2 is $2" cat $2 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l echo "English classes offered:" cat $2 | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'ENGL' | wc -l fi else if [ $# -gt 2 ] then i=1 for x in $*;do echo "argument $i is $x" let i=i+1 cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | wc -l echo "English classes this semester:" cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'ENGL' | wc -l echo "Math classes this semester:" cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'MATH' | wc -l echo "Computer Science classes this semester:" cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'CSCS' | wc -l echo "Biology classes this semester:" cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'BIOL' | wc -l # echo "Fitness classes this semester:" # cat $x | grep 'ddtitle' | sed 's///g' | sed 's/<\/a>.*$//g' | grep 'PFIT' | wc -l done fi fi fi fi =====Execution===== lab46:~/src/SysProg$ sh semesterscript.sh No arguments entered, changing to semesterfiles/ to get data lab46:~ =====Reflection===== Save everything! The bulk of the code used with this project was written last semester in my unix class. Also, documentation is important! I had a side file filled witht he documentation for the file, and it reminded me of the syntax for the bash commands.