24.07.2018 Views

Bash-Beginners-Guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

find-and-replace actions on lines containing a pattern.<br />

5.5. Exercises<br />

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

These exercises are meant to further demonstrate what sed can do.<br />

1. Print a list of files in your scripts directory, ending in ".sh". Mind that you might have to unalias<br />

ls. Put the result in a temporary file.<br />

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

temporary file.<br />

3. Delete the first 3 lines of each temporary file.<br />

4. Print to standard output only the lines containing the pattern "an".<br />

5. Create a file holding sed commands to perform the previous two tasks. Add an extra command to this<br />

file that adds a string like "*** This might have something to do with man and man pages ***" in the<br />

line preceding every occurence of the string "man". Check the results.<br />

6. A long listing of the root directory, /, is used for input. Create a file holding sed commands that<br />

check for symbolic links and plain files. If a file is a symbolic link, precede it with a line like "--This<br />

is a symlink--". If the file is a plain file, add a string on the same line, adding a comment like "

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!