======Part 2====== =====Entries===== ====Entry 1: October 10th, 2012==== Today we covered scripting and created a "self-aware" script. This script will store the name of the user and remember his name, without asking again, if the script is used again on the same terminal. The script is as follows: #10-10script #!/bin/bash # name="`cat ${0}.conf | grep '^name=' | cut -d'=' -f2 2>/dev/null`" if [ -z "${name}" ]; then echo -n "Who are you?" read name echo "Pleased to meet you, $name" echo "name=$name" > ${0}.conf elif [ ! -z "${1}" ]; then if [ ! "$name" = "$1" ];then echo "Intruder!" fi else echo "Welcome back, ${name}" fi The use of 'f2' stands for the second field of an input, meaning it is the entry following the space after the originating command. Lab46:~$ ./script5 bob abc f1(field1)= './script5' f2(field2)= 'bob' f3(field3)= 'abc' ====Entry 2: October 12th, 2012==== In today's class we touched base on some C programming language and explored the four different Programming Paradigms; 1.) Structured/Imperative/Procedural - C, Bash, C++, PHP, Python, Visual Basic 2.) Functional - LISP 3.) Logical -Prolog, Haskell 4.) Object Oriented - C++, Java, Python, Eiffel, Smalltalk Our first step into programming with the C language was the expected 'Hello World!' program which demonstrates output. The stated program is as follows; #include int main() { printf("Hello, World! \n"); return (0) } ====Entry 3: October 19, 2012==== - Today we covered the use of grep, used to pull files matching the name, and sed, used to replace a pattern with something else. - This was extremely useful knowledge because it will help with data management later on in the course. - I wonder how exactly to set the parameters used with these operations in order for them to work efficiently. lab46:~/src/class$ cat spring2013-20121026.html | grep '^Orientation to Technology - 90227 - TECH 1050 - 001 LabVIEW Programming - 90509 - TECH 1060 - 001 Manufacturing Methods Lab - 89682 - TECH 1080 - 001 Tech Word Process & Research - 89648 - TECH 1110 - 001 ====Entry 4: October 24, 2012==== - Today we covered the use and application of Regular Expressions along with Extended Regular Expressions. - These will be vital in setting parameters for managing data. Listed below are the expression and their use; Regular Expressions: ^ -match beginning of line $ -match end of line \< -match beginning of word \> -match end of word . -match any single character * -0 or more of previous [] -character class: match any of enclosed [^] -inverted " ": do not match any of enclosed Extended Regular Expressions: () - used for grouping | - or =====Keywords===== {{page>unixpart2&nofooter}} =====Experiment 2===== ====Question==== How can I sort a large list of files into a sorted list of legible text, using a single line of code? ====Resources==== The Lair at www.pureawesomestation.com/fakewebaddress/obviously ====Hypothesis==== I know for a fact that it can be done, using the knowledge I already have along with things I will shortly learn. I predict the experiment will be a success. ====Experiment==== How are you going to test your hypothesis? What is the structure of your experiment? I will use the course list of the 2012-2013 year as the victim of this experiment, I have copied it into my class directory prior to the beginning of this experiment. 1. Display the content of the html file a.) cat spring2013-20121026.html 2. Decide how to sort the files in question. a.) I will sort the according to class subject. b.) Using a combination of cat, grep, and sed, organize the data accordingly. 3. Document the input, and state success. ====Data==== Lab46:~$ cat spring2013-20121026.html | egrep '^Contemplative Meditation - 89752 - WELL 1505 - 002 Introduction to Winemaking - 89574 - WINE 1010 - 001 Tutor in Writing Center I - 89633 - WRIT 1701 - 001 Tutor in Writing Center I - 90233 - WRIT 1701 - 002 Lab46:~$ cat spring2013-20121026.html | egrep '^//g' --- shorten the output into a more manageable/legible format. -Output example: Contemplative Meditation - 89752 - WELL 1505 - 002 Introduction to Winemaking - 89574 - WINE 1010 - 001 Tutor in Writing Center I - 89633 - WRIT 1701 - 001 Tutor in Writing Center I - 90233 - WRIT 1701 - 002 lab46:~/src/class$ cat spring2013-20121026.html |grep '^//g' |sed 's/<\/A><\/TH>$//g'| sed 's/^\(.*\) - \([0-9][0-9][0-9][0-9][0-9]\) - \(.*\) - \([0-9]*\)$/\3-\4:\2:\1/g' ---Rearrange data into an alphabetic format, with the subject first and the class name last on the line. -Output example: WELL 1505-002:89752:Contemplative Meditation WINE 1010-001:89574:Introduction to Winemaking WRIT 1701-001:89633:Tutor in Writing Center I WRIT 1701-002:90233:Tutor in Writing Center I ====Analysis==== Based on the data collected: * Was your hypothesis correct? - Yes, I knew it was possible. * Was your hypothesis not applicable? - I suppose so since my hypothesis was success, Matt is the teacher I cannot fail! * Is there more going on than you originally thought? (shortcomings in hypothesis) - Yes, variables used exceeded my current knowledge, I had to seek out assistance from the teacher of the course. * What shortcomings might there be in your experiment? - I needed to seek assistance in order to complete it, taking away from the feeling of self-accomplishment. * What shortcomings might there be in your data? - I did not provide the full data output in the data section as it would not all fit. ====Conclusions==== I found out that any kind of sorting can be done using one line, as long as pipes, cat, sed, and grep, operations are all used correctly. Both Regular Expressions and Extended Regular Expressions are used to set the parameters used in sorting the data.