Sed copies each line of input into a pattern space. Sed instructions consist of addresses and editing commands. If the address of the command matches the line in the pattern space, then the command is applied to that line. If a command has no address, then it is applied to each input line. If a command changes the contents of the space, subsequent command-addresses will be applied to the current line in the pattern space, not the original input line.
address can be either a line number or a pattern , enclosed in slashes (/ pattern /). A pattern is described using a regular expression. Additionally, \n can be used to match any newline in the pattern space (resulting from the N command), but not the newline at the end of the pattern space.
If no pattern is specified, the command will be applied to all lines. If only one address is specified, the command will be applied to all lines matching that address. If two comma-separated addresses are specified, the command will be applied to a range of lines between the first and second addresses, inclusively. Some commands accept only one address: a , i , r , q , and = .
The opening curly brace must end a line, and the closing curly brace must be on a line by itself. Be sure there are no spaces after the braces.
The following table lists the pattern-matching metacharacters that were discussed in Chapter 3, Understanding Regular Expression Syntax .
Note that an empty regular expression "//" is the same as the previous regular expression.