Sed - An Introduction and Tutorial by Bruce Barnett
|
One use of the hold buffer is to remember previous lines. An example of this is a utility that acts like?grep?as it shows you the lines that match a pattern. In addition,it shows you the line before and after the pattern. That is,if line 8 contains the pattern,this utility would print lines 7,8 and 9. One way to do this is to see if the line has the pattern. If it does not have the pattern,put the current line in the hold buffer. If it does,print the line in the hold buffer,then the current line,and then the next line. After each set,three dashes are printed. The script checks for the existence of an argument,and if missing,prints an error. Passing the argument into the?sed?script is done by turning off the single quote mechanism,inserting the "$1" into the script,and starting up the single quote again: #!/bin/sh # grep3 - prints out three lines around pattern # if there is only one argument,exit Click here to get file:? You could use this to show the three lines around a keyword,i.e.: grep3 vt100
|

