Table of Contents
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 <stdio.h> 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 '^<TH CLASS="ddtitle"' <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=90227">Orientation to Technology - 90227 - TECH 1050 - 001</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=90509">LabVIEW Programming - 90509 - TECH 1060 - 001</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=89682">Manufacturing Methods Lab - 89682 - TECH 1080 - 001</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=89648">Tech Word Process & Research - 89648 - TECH 1110 - 001</A></TH>
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 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
Keywords
unix Keyword 2
processes
Definition
Processes- programs or instances that operate concurrently with one another to produce a result.
References
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
- Reference 1: http://en.wikipedia.org/wiki/Process_%28computing%29
- Reference 2: http://www.thefreedictionary.com/Processes
- Reference 3: http://www.merriam-webster.com/dictionary/process
unix Keyword 2 Phase 2
dot files
Definition
A dot file is a file that is not normally visible using a basic ls command. These files tend to be configuration files for other programs, but not always.
References
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
- http://www.cyberciti.biz/faq/bash-shell-display-only-hidden-dot-files/
Demonstration
Demonstration of the indicated keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ ls -a . .pinerc Pictures .. .profile Public .Xauthority .recently-used.xbel Templates .addressbook .ssh Videos .bash_history .swn abcdefghijklmnopqrstuvwxzy .bash_logout .swo archive1.tar.gz .bashrc .swp archive2.zip .cache .vim archives .config .viminfo closet .dbus .vimrc file.c .fluxbox .xinitrc file.gz .gstreamer-0.10 .xsession-errors minecraft.jar .gvfs Desktop public_html .indent.pro Documents src .irssi Downloads the answer.txt .local Maildir .pine-passfile Music
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
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 '^<TH CLASS="ddtitle"' --- shows all classes, ussing the default layout pattern <TH CLASS="ddtitle" (SUCCESS) -Output example: <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=89752">Contemplative Meditation - 89752 - WELL 1505 - 002</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=89574">Introduction to Winemaking - 89574 - WINE 1010 - 001</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=89633">Tutor in Writing Center I - 89633 - WRIT 1701 - 001</A></TH> <TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&crn_in=90233">Tutor in Writing Center I - 90233 - WRIT 1701 - 002</A></TH> Lab46:~$ cat spring2013-20121026.html | egrep '^<TH CLASS="ddtitle"'| sed 's/^<TH CLASS.*crn_in=.....">//g' --- shorten the output into a more manageable/legible format. -Output example: Contemplative Meditation - 89752 - WELL 1505 - 002</A></TH> Introduction to Winemaking - 89574 - WINE 1010 - 001</A></TH> Tutor in Writing Center I - 89633 - WRIT 1701 - 001</A></TH> Tutor in Writing Center I - 90233 - WRIT 1701 - 002</A></TH> lab46:~/src/class$ cat spring2013-20121026.html |grep '^<TH CLASS="ddtitle"' | sed 's/^.*crn_in=.....">//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.