A.2 Syntax of sed CommandsSed commands have the general form:
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. A.2.1 Pattern Addressingaddress 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 ! operator following an address causes sed to apply the command to all lines that do not match the address. Braces ({}) are used in sed to nest one address inside another or to apply multiple commands at the same address.
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. A.2.2 Regular Expression Metacharacters for sedThe 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.
|
|