Perform this exercise within your home directory on the remote server.
Create a file with these contents:
Line one. The second line. The third. This is line four. Five. This is the sixth sentence. This is line seven. Eighth and last.
1. Produce output from this file in which every occurrence of "line" is replaced with "sentence". Do it three different ways. First, run sed at the command line giving it the command that does the job. Second, put the sed command into a file called subs_demo, then run sed from the command line, referring it to subs_demo. And third by copying subs_demo under the name subs_demo.sed and converting that file to a sed interpreter script, to be run directly from the bash prompt without argument. Don't forget to make subs_demo.sed executable. The output should be identical in all three cases.
In the examples below use the second method, putting the sed command into a file and using it by running sed from the command line (as opposed to creating a sed interpreter script).
2. Write the sed command that will append a line reading "AFTER." following every line that contains the word "line". Name the file append_demo.
3. Write the sed command that will insert a line reading "BEFORE." preceding every line that contains the word "This". Name the file insert_demo.
4. Write the sed command that will change lines 2 through 4 to read as follows:
SED WILL INSERT THESE THREE LINES IN PLACE OF THE SELECTED LINES.
Name your file change_demo.
5. Write the sed commands, in a file, that will cause all lines except the 3rd to be printed. Name the file next_demo1.
6. Write the sed commands, in a file, that will cause all lines except those containing "the" to be printed. Name the file next_demo2.
7. Write the sed command that will find lines containing "line", replace each such occurrence with "sentence", and write those (altered) lines into a file named "temp". Name your file "write_demo1".
8. Write the sed command that will output lines 2 through 4 into a file named "temp2". Name your file "write_demo2".
9. Write the sed command that will output all lines except 2 through 4 into a file named "temp2". Name your file "write_demo3".
These examples from A Practical Guide to Linux, Mark Sobell