Exercises

5.5. Exercises

These exercises are meant to further demonstrate what sed can do.

  1. Print a list of files in your scripts directory, ending in ".sh". Mind that you might have to unalias ls. Put the result in a temporary file.

  2. Make a list of files in /usr/bin that have the letter "a" as the second character. Put the result in a temporary file.

  3. Delete the first 3 lines of each temporary file.

  4. Print to standard output only the lines containing the pattern "an".

  5. Create a file holding sed commands to perform the previous two tasks. Add an extra command to this file that adds a string like "*** This might have something to do with man and man pages ***" in the line preceding every occurence of the string "man". Check the results.

  6. A long listing of the root directory, /, is used for input. Create a file holding sed commands that check for symbolic links and plain files. If a file is a symbolic link, precede it with a line like "--This is a symlink--". If the file is a plain file, add a string on the same line, adding a comment like "<--- this is a plain file".

  7. Create a script that shows lines containing trailing white spaces from a file. This script should use a sed script and show sensible information to the user.


216 visits (1 today, 8 this week, 40 this month, 216 this year)
Uptime: 19:26:17 up 10 days, 1:09, 7 users, load average: 0.00, 0.54, 5.72
3.128.30.199 GET from server z.larryforalaska.com

Friday, December 27, 2024 @ 7:26:17 PM
z.ServerAdmin@lam1.us