Assignment 4
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:
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 Cgrep -c ism$ $wdemonstrates that 325 words in that file end with 'ism.'