Assignment 4

Note: this assignment may migrate a bit (to correct file names and such). As of March 9th, you can assume that the assignment is in its final form, but as of February 19th, all of the problems you see here will be included in the final version (so there is no reason not to get started!).

Same instructions as always.

id est: be sure to restate the problem, the steps you used to produce an answer, the answer you found. Verify that the answer you found is correct and show the steps used to verify.

Set A: For these problems, use a text file (which we'll refer to as file1 here) that you create using these rules:

Use nano or another editor to create a file containing a  paragraph or two (6 to 8 lines) of text (written by you). This should consist of real English sentences which have at least some degree of literary cohesion. As examples, it could be the beginning to a short story you would like to write some day, the story of your life, a letter to a friend, an essay on copyright law, advice to dog owners, a humorous account of a botched romance or anything generally resembling prose. I'll not be grading for grammar, spelling, authenticity, or literary merit, so long as the above definitions are satisfied. Output the file to the screen using cat.0

1. Use sed to rewrite all spaces within the file as periods. (The preceding sentence would appear as 'Use.sed.to.rewrite.all.spaces.within.the.file.as.periods.'.)

2. Extra credit. Use sed to capitalize the last letter of each word that begins with either 'a' or 't'. [Hint: remember the string which was found. Consider using sed y and or tr ]

3. Use sed or cut to output just the first three words of each line.

4. Write each word of file1 on a different line. (show the commands as well as the first 10 and last 10 lines of output)

5. Determine how many different words there are in file1. The words 'the' and 'The' are considered, in English, to be the same word. Likewise, puncutation other than apostrophes and hyphens is generally not considered to be part of the word. (E.g., in the phrases "Happiness, once found, is never lost" and "Bliss is happiness."  The word represented by the string "Happiness," is the same as the word in "happiness." ) Determine the frequency with which each word in file1 is used within file1. Write a file containing just the different words.

6. Using a loop, take each different word that has three or more letters in file1 and determine how many words in the dictionary (use /home/SRUNET/david.dailey/words or one of your choice from those described in lecture notes)  begin with that word as a prefix. For example,

91 of the words in /home/SRUNET/david.dailey/words begin with the letters "the" including these four:

$paste <(grep -i ^the $w|head -2) <(grep -i ^the $w|tail -2)
the     they're
thearchy        they've

Set B: For these problems, create and use a new subdirectory called 'projectB'.

1. Using a command or script, create 45 files in projectB using filenames consisting of the 45 words in the dictionary (/home/SRUNET/david.dailey/words) that end in 'ort'.

2. Use a single command to remove all files with names started with the letter 's' inside 'projectB'.

3. There are 598 words ending in 'ort' in /usr/share/dict/words. Use a command to determine how many of these begin with lower case letters.

4. There are 865 words in /home/SRUNET/david.dailey/words that end in 'ate'. How many begin with each of the letters a, t and e? Provide an example of each (of those three letters).

5. There are 808 words in /home/SRUNET/david.dailey/words that end in 'ity' including these:

$ grep ity$ $w|head -3
ability
abnormality
abnormity

Exactly 20 of those words remain words (in that dictionary) after changing the 'ity' to ify'  including these:

clarify (clarity)
complexify (complexity)
deify (deity)
dignify (dignity)
diversify (diversity)
identify (identity)

Write a command which finds exactly those 20 words.

Set C

1. In the file $w=/home/SRUNET/david.dailey/words, the command
grep -c ism$ $w
demonstrates that 325 words in that file end with 'ism.'

The ending 'tic' occurs more frequently, appearing at the end of  336 words. How can you find the 14 three letter endings that
serve as endings to more words than 'ism'? As always, show commands used, the output found and steps used to verify correctness.

2. The file s=/home/SRUNET/david.dailey/data/es.txt contains word frequency lists (from Invoke IT Limited) for Spanish language text (apparently sampled from Internet social media).  Not all of the 535232 words contained therein are legitimate parts of Spanish vocabulary.
You may need to set your putty language settings (under Change Settings/Window/Translation) to UTF-8 to be able to see the characters as expected.
Among the 100,000 most frequently used words in that list (head -100000 $s) find which 30 characters (Spanish letters) begin words most often. Find the commands to output just those 30 characters (separated by spaces instead of carriage returns).

3.  The data in /home/SRUNET/david.dailey/data/dist_all_last contains the 88,800 last names (surnames) which were (as of the 1990 census) most common among residents of the US and its territories.  If those names are categorized by the letter (A through Z) that the name begins with, what five letters begin the most names?  Is this ordering any different for the 1000 most common last names? If so what would you conclude about any differences. Hint: a deeper analysis (possibly involving additional commands and inquiries) is better, so long as it remains objective.