Regular Expressions

Assignment 2

For each of the following questions use the appropriate command line. Enter the command line in the space provided. Due October 1, 2004. When you are done you can check your answers.

  1. Use cut to display only the file size and file name from the output of the command 'ls -l /etc'.
  2. Use cut to display only the home directories of users from the file /etc/passwd and save it in a file called 'home.txt'. Do the same with the field that contains the name of the default shell (eg. /bin/bash) and save it to a file called 'shell.txt'.
  3. From the files above use 'paste' to create a file that contains lines with a shell and the corresponding home directory into a file called 'pasted.txt'.
  4. Translate all z to a, r to T, and m to 2.
  5. Convert the entire 'callofthewild.txt' document to uppercase.
  6. Create a cryptogram from a paragraph of text stored in a file called 'text.txt' and save it in a file called 'crypt.txt'. A cryptogram has one letter substituted for another to produce an unreadable code. They are usually in all uppercase with spacing and punctuation left intact.
  7. Use sed to change the string 'Judge' to 'Mr.' in 'callofthewild.txt'.
  8. Using sed, add ', the bad dog, ' after each occurrence of 'Spitz' in lines 123 to 567 in 'callofthewild.txt'.
  9. Using sed, on lines that contain both 'Buck' and 'Spitz', add ', our hero, ' after 'Buck' in 'callofthewild.txt'.
  10. With sed you can use more than one editing instruction if you use the -e option before each one. Use only sed to change 'read' to 'eat' on lines that contain 'Buck' and 'newspapers', then display only the lines that contain 'North'.