12.3. Syntax of sed Commandssed commands have the general form: [address[,address]][!]command [arguments] sed commands consist of addresses and editing commands. commands consist of a single letter or symbol; they are described later, alphabetically and by group. arguments include the label supplied to b or t, the filename supplied to r or w, and the substitution flags for s. addresses are described in the next section. 12.3.1. Pattern AddressingA sed command can specify zero, one, or two addresses. An address can be a line number, the symbol $ (for last line), or a regular expression enclosed in slashes (/pattern/). Regular expressions are described in Chapter 9, "Pattern Matching". 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.
12.3.1.1. Exampless/xx/yy/g Substitute on all lines (all occurrences) /BSD/d Delete lines containing BSD /^BEGIN/,/^END/p Print between BEGIN and END, inclusive /SAVE/!d Delete any line that doesn't contain SAVE /BEGIN/,/END/!s/xx/yy/g Substitute on all lines, except between BEGIN and END Braces ({}) are used in sed to nest one address inside another or to apply multiple commands at the same address: [/address/[,/address/]]{ command1 command2 } 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 blank spaces after the braces. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|