Updated: 2015-09-06 00:48 EDT
Do not print this assignment on paper!
- On paper, you will miss updates, corrections, and hints added to the online version.
- On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.
- On paper, scrolling text boxes will be cut off and not print properly.
23h59 (11:59pm) Friday October 10, 2014 (end of Week 6)
Do not print this assignment on paper! On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.
This is an overview of how you are expected to complete this assignment. Read all the words before you start working.
For full marks, follow these directions exactly.
You are given a file of somewhat random text, and a set of descriptions of sets of lines in that file. For each description, you are to produce a grep -E
command with one single extended regular expression that will select the described set of lines. You will initially test your regular expressions on the interactive shell command line, and when you are satisfied with each one, you will put the command you used into a shell script.
You can use a Checking Program to check your work as you do the tasks. You can check your work with the checking program as often as you like before you submit your final mark. (Some tasks sections below require you to finish the whole section before running the checking program; you may not always be able to run the checking program successfully after every single task step.)
Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.
You will create file system structure in your HOME directory on the CLS, with various directories, files, and links. When you are finished the tasks, leave these files, directories, and links in place as part of your deliverables on the CLS. Do not delete any assignment work until after the term is over! Assignments may be re-marked at any time; you must have your term work available right until term end.
All references to the “Source Directory” below are to the CLS directory ~idallen/cst8177/14f/assignment04/
and that name starts with a tilde character ~
followed by a userid with no intervening slash. The leading tilde indicates to the shell that the pathname starts with the HOME directory of the account idallen
(seven letters).
The previous term’s course notes are available on the Internet here: CST8207 GNU/Linux Operating Systems I. All the notes files are also on the CLS. You can learn about how to read and search these files using the command line on the CLS under the heading Copies of the CST8207 course notes near the bottom of the page Course Linux Server.
Do a Remote Login to the Course Linux Server (CLS) from any existing computer, using the host name appropriate for whether you are on-campus or off-campus. All work in this assignment must be done on the CLS.
Make an assignment04
directory in the same directory as you made assignment02
in a previous assignment.
This
assignment04
directory is the Base Directory for most pathnames in this assignment. Store your files and answers in this Base Directory.
Follow the instructions in the first two steps at the start of Checking Program below to create a working symbolic link to the executable Checking Program.
The input text file test_input.txt
in the Source Directory contains many lines of text. Put a soft link to this input file in your Base Directory. Use the same name for the link.
Check your work so far using the checking program symlink.
Below, in the Labelled Descriptions section, you are given labelled descriptions of lines to find in the input text file test_input.txt
. For each labelled description you will repeat these two steps (described in detail below):
On the command line, invent a grep -E
command using a single extended (not basic) regular expression that will select and display only the described lines of text, and nothing more, from the input file.
Do not use any other options to grep
. Use extended regular expression syntax appropriate for -E
. You do not need multiple expressions. For example, if you’re looking for phone numbers, your regular expression will look for lines that contain a single phone number (not multiple numbers) and nothing else.
Hints: There are example lines given for each labelled description that you must match, and lines that you must not match. Test your expression against these lines before you test it against the large test file. (Save the example lines in a file for repeated use.)
Put the working grep -E
command into its own shell script.
Each set of lines to be found is labelled below with a label. The label is the first word in the section, followed by a colon. For example, the following example description is labelled bar:
bar: lines that consist of (only) the single word barbar and nothing else
Repeat the following steps for each of the labelled descriptions:
Make your current working directory the Base Directory (the directory containing the new symlink you made to the test_input.txt
file) if it is not already so.
Read carefully the label and description of the kind of lines that must be matched. You must write a single grep -E
command with a single extended regular expression pattern and no other options.
There are example lines given for each labelled description that you must match, and lines that you must not match. Test your expression against these example lines before you test it against the large test file. Hint: Save the example lines in a file for repeated use.
Type directly at the command line your initial attempt at a grep -E
command that finds the lines, and view the result on your screen. No pipes or other options are allowed. Use only a single grep -E
command with a single extended regular expression.
If you’re not satisfied with the output you see, use up-arrow to retrieve the previous command, and make changes to the regular expression, then re-run the new command. Repeat the this step over and over on the interactive command line until you’re satisfied with the output on your screen and want to check your answer.
When you are confident that your expression is correct, find lines in the large test_input.txt
file and verify the checksum.
For the example given above with the label bar
, a grep -E
command that would work would be:
$ grep -E '^barbar$' test_input.txt
The following would all be incorrect solutions:
$ grep -E 'barbar$' test_input.txt # WRONG
$ grep -E '^barbar' test_input.txt # WRONG
$ grep -E 'barbar' test_input.txt # WRONG
$ grep -E '^.*barbar.*$' test_input.txt # WRONG
$ grep -E '^ *barbar *$' test_input.txt # WRONG
$ grep -E '^Barbar$' test_input.txt # WRONG
$ grep -E -w '^barbar$' test_input.txt # WRONG
$ grep -E -i '^barbar$' test_input.txt # WRONG
The correct lines of output on your screen for each problem below will vary between a few and a few hundred lines, depending on the problem.
To check your answer, use up-arrow to retrieve the command, and modify it to pipe the output of your command into the wc
program, then do the same, changing wc
to sum
. Compare the output of wc
and sum
with the expected values output by the Checking Program.
For the example given above with the label bar
, the checking pipelines would be done like this, in this order:
$ grep -E '^barbar$' test_input.txt
$ grep -E '^barbar$' test_input.txt | wc
$ grep -E '^barbar$' test_input.txt | sum
The '^barbar$'
string is the quoted extended regular expression.
If the word count or checksum values differ from those expected values output by the Checking Program, you need to fix your regular expression. Use up-arrow to retrieve the command, make your changes to the regular expression, and re-run the command until you get it right. Hint: Always check your expression against the given example lines first, before you test against the large input file.
Do not save the output of the Checking Program; the test file may change at any time to include new test cases, so the word count and checksums may change at any time.
When you are satisfied with your answer as typed on the command line, use a text editor to create in your Base Directory an executable shell script whose name is the label name followed by an .sh
extension, e.g. bar.sh
. Copy the working grep -E
command from the command line into the last line of the new shell script. Only put the grep -E
command into the script, not any pipelines or checking. This executable script must run only your grep -E
command using test_input.txt
as the file name.
For the example given above with the label bar
, the script name must be bar.sh
in the Base Directory.
The first few lines of every shell script must correspond exactly to the Script Header described in class.
The last line of every script will be your grep -E
command. Do not redirect or pipe the output of your command into anything – the script should produce the correct lines of output from test_input.txt
on your screen so that it can be checked.
Do not put any lines into your script other than the Script Header, the single grep -E
command line, and optional blank or comment lines.
You can also check the output of your script using the wc
and sum
commands, similar to the way you checked the original grep
command. The script must output exactly the same lines as the original grep
command that you put into it. The results should be identical:
$ grep -E '^barbar$' test_input.txt | wc
$ ./bar.sh | wc
$ grep -E '^barbar$' test_input.txt | sum
$ ./bar.sh | sum
Repeat the 8 steps in this section for each of the Labelled Descriptions below.
NOTE: When it comes time to create your second and subsequent scripts, copy the previous script to the new label name rather than starting from scratch every time. Run the Checking Program to make sure you have copied the Script Header correctly.
Do not put any lines into your script other than the Script Header, the single grep -E
command line, and optional blank or comment lines.
Your scripts must give the correct output word count and checksum results when searching in this test_input.txt
test file. If the output is incorrect, you will be told what the correct values should be in the error message. Do not save this message – the testing file may change at any time during the assignment and your scripts must still match the correct lines.
Write the extended regular expressions to match the given pattern specifications, not to match the particular set of lines in the given test file(s). I may come up with other test cases even after the due date of the assignment; your script loses marks if it fails these tests because it doesn’t do what the specification says it must do. You may have to write your own test cases, to be sure you got it right.
I’ve also set up the checking program to detect failure to protect special characters from shell GLOB expansion. If your expression works in your account but not when the checking script runs it, this may be your problem. You may also see “Permission denied” errors if this is the problem. Fix your script to hide special characters from the shell.
grep -E
other than --color
.[a-z]
or [0-9]
) due to problems with Internationalization. Always use the POSIX character class names instead of ranges.All the points below have the following format:
label
: description of desired grep -E
output from in file test_input.txt
Here are the names of the patterns (and scripts) you must create:
names
: Lines consisting of a single name of a person, capitalized, with capitalized optional middle name, separated by a single space. Any alphabetic string is acceptable as a name. These should match
John Smith
John Yeardly Smith
A B
A B C
Aabc Cdef Z
Abc Def Ghi
Abc Def
These should not match
john Smith
John Smith
John YeardlySmith
a B
A b C
A B c
A b
abc Def
Abc Def ghi
A B C
A B C D
Abc Def G hi
zipcode
: Lines consisting of a single numeric USA zip code of the form 99999
or 99999-9999
, with zeros allowed everywhere. These should match
12345
00000
01234
23456-0000
99999-0001
00000-0000
These should not match
123456
1233-4444
000-00000
2345-34568
23456-34568
hour12
: Lines consisting of a single one or two digit integer between 1 and than 12 (inclusive), for valid 12-hour times. Hint: create one regular expression that matches numbers between 1 and 9, and another regular expression that matches numbers between 10 and 12, and combine those with alternation. (Note: 0
is not a valid 12-hour time.)
These should match
1
01
2
02
9
09
10
11
12
These should not match
0
00
20
13
90
001
011
120
012
daynum
: Lines consisting of a single integer between 1 and 31, for a valid day of a month. Hint: create one regular expression that matches numbers between 1 and 9 with optional leading zero, and another that matches numbers between 10 and 29, and one that matches numbers between 30 and 31, then use alternation to combine those three.
These should match:
1
01
9
09
10
20
30
31
These should not match
0
00
001
100
32
031
310
56
33
100
hour24
: Lines consisting of a single non-negative integer less than 24, for a valid hour in 24-hour times. Hint: See the hints for the previous questions.
These should match:
0
1
2
3
00
01
05
09
10
15
20
23
These should not match:
000
100
023
009
012
24
25
045
minutes
: Lines consisting of a single two digit integer less than 60, for valid minutes or seconds in a time.
These should match
00
01
09
10
11
20
30
59
These should not match
000
010
200
60
070
0
9
90
1
decimal
: Lines consisting of a single unsigned decimal or floating point number.
These should match
000
0000.0000
8.45
2.768
0.320
.320
96
These should not match
.
45.
1..2
<empty line>
currency
: Lines consisting of a single dollar amount, starting with the leading dollar sign and optional two-digit cents.
These should match
$0
$1
$12
$.12
$0.12
$0000.12
$1234.56
These should not match
1
12
.12
0.12
1234.56
1.
1.2
1.23
$
$.
$.1
$1.2
$1.234
date
: Lines consisting of a single date with syntax YYYY-MM-DD
where the year (YYYY
) is exactly 4 digits, the month (MM
) is between 1 and 12, two digits maximum, and the day (DD
) is between 1 and 31, two digits maximum. The day does not have to be accurate for February, June, leap years, etc.; it only has to be a number between 1 and 31, two digits maximum. Hint: Combine and re-use your work and hints from earlier questions!
These should match
0000-01-01
2014-1-1
2014-1-15
2014-01-31
2014-02-31
0000-6-31
2014-12-31
These should not match
0000-00-00
0000-00-01
2000-13-01
2000-12-00
20000-12-01
2000-012-12
2000-12-012
2000-12-120
2014-01-32
time24hr
: Lines consisting of a single 24-hour time with optional seconds with syntax HH:MM[:SS]
where minutes and seconds must have exactly two digits.
These should match
02:23
2:23
2:23:59
12:23:59
23:23
00:00:00
00:00
00:00:59
01:01:01
These should not match
24:00
12:60:00
12:34:56:00
12:15:60
012:14:00
11:59:001
11:059
11:059:1
10:1:10
time12hr
: Lines consisting of a single 12-hour based time with optional seconds and AM/PM using syntax HH:MM[:SS][am|AM|pm|PM]
where minutes and seconds must have two digits, followed by an optional am
, pm
, AM
, or PM
. Hint: Use re-use parts of your hour12
and minute
regular expressions from above in your answer. (Note: 00:00am
is not a valid 12-hour time.)
These should match
2:24pm
2:24
2:24PM
2:24AM
2:24am
02:34
12:59
12:56:59
4:56:56
These should not match
0:00
00:00
00:01
00:00am
00:59:59PM
99:99
002:23
13:01am
23:01PM
2:3pm
1:2:3pm
2:24pmpm
2:24amPM
2:23Pm
2:23pM
2:23aM
2:23Am
23:23
12:23:76
12:60:34
1:1
1:1:1
10:1:10
ipaddr:
Lines consisting of a single IPV4 Address of four integers from 0 to 255 separated by dots. Each integer should be three digits or less, and leading zeros are OK.
Hint: break each of the four integers into an alternation between the following ranges: integers greater or equal to 200 and less than or equal to 255 (which could be done as one group 200 through 249 and a second group 250 through 255), integers from 100 to 199, integers from 10 to 99, integers from 0 to 9.
These should match
255.255.255.255
1.1.1.1
02.089.89.001
0.0.0.0
00.01.002.000
23.234.123.123
12.12.12.12
012.012.012.012
These should not match
1.1.1.
1.
1.1
1.1.1.1.1
0234.1.1.1
234.0234.166.23
1.1.1
345.2.2.2
299.2.2.2
Check your work so far using the checking program symlink.
Do not save the
wc
andsum
output of the Checking Program; the test file may change at any time to include new test cases, so the word count and checksums may change at any time.
That is all the tasks you need to do.
Read your CLS Linux EMail and remove any messages that may be waiting. See [Reading eMail] for help.
Check your work a final time using the Checking Program and save the standard output as described below. Submit your mark following the directions below.
Summary: Do some tasks, then run the checking program to verify your work as you go. You can run the checking program as often as you want. When you have the best mark, upload the marks file to Blackboard.
Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.
There is a Checking Program named assignment04check
in the Source Directory on the CLS. Create a Symbolic Link to this program named check
under your new Base Directory on the CLS so that you can easily run the program to check your work and assign your work a mark on the CLS. Note: You can create a symbolic link to this executable program but you do not have permission to read or copy the program file.
Execute the above check
program on the CLS using its symbolic link. (Review the Search Path notes if you forget how to run a program by pathname from the command line.) This program will check your work, assign you a mark, and display the output on your screen. (You may want to paginate the long output so you can read all of it.)
You may run the check
program as many times as you wish, to correct mistakes and get the best mark. Some task sections require you to finish the whole section before running the checking program at the end; you may not always be able to run the checking program successfully after every single task step.
assignment04.txt
under your Base Directory on the CLS. Use that exact name. Case (upper/lower case letters) matters. Be absolutely accurate, as if your marks depended on it.
YOUR MARK for
assignment04.txt
file from the CLS to your local computer and verify that the file still contains all the output from the checking program. Do not edit this file! No empty files, please! Edited or damaged files will not be marked. You may want to refer to your File Transfer notes.
YOUR MARK for
assignment04.txt
file from your local computer to the correct Assignment area on Blackboard (with the exact name) before the due date:
Use only Attach File on the Upload Assignment page. Do not enter any text into the Text Submission or Comments boxes on Blackboard; I do not read them. Use only the Attach File section followed by the Submit button. If you need to comment on any assignment submission, send me EMail.
You can revise and upload the file more than once using the Start New button on the Review Submission History page to open a new Upload Assignment page. I only look at the most recent submission.
You must upload the file with the correct name from your local computer; you cannot correct the name as you upload it to Blackboard.
You will also see the Review Submission History page any time you already have an assignment attempt uploaded and you click on the underlined assignment04 link. You can use the Start New button on this page to re-upload your assignment as many times as you like.
You cannot delete an assignment attempt, but you can always upload a new version. I only mark the latest version.
Your instructor may also mark files in your directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete any assignment work from the CLS until after the term is over!
I do not accept any assignment submissions by EMail. Use only the Blackboard Attach File. No word processor documents. Plain Text only.
Use the exact file name given above. Upload only one single file of Linux-format plain text, not HTML, not RTF, not MSWord. No fonts, no word-processing. Linux plain text only.
NO EMAIL, WORD PROCESSOR, PDF, RTF, or HTML DOCUMENTS ACCEPTED.
No marks are awarded for submitting under the wrong assignment number or for using the wrong file name. Use the exact 16-character, lower-case name given above.
WARNING: Some inattentive students don’t read all these words. Don’t make that mistake! Be exact.
READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!