📄 psed.1
字号:
.RS 4.IP "\fBg\fR" 8.IX Item "g"The replacement is performed for all matching, non-overlapping substringsof the pattern space..IP "\fB1\fR..\fB9\fR" 8.IX Item "1..9"Replace only the n\-th matching substring of the pattern space..IP "\fBp\fR" 8.IX Item "p"If the substitution was made, print the new value of the pattern space..IP "\fBw\fR \fIfile\fR" 8.IX Item "w file"If the substitution was made, write the new value of the pattern spaceto the specified file..RE.RS 4.RE.IP "[2addr]\fBt\fR [\fIlabel\fR]" 4.IX Item "[2addr]t [label]"Branch to the \fB:\fR function with the specified \fIlabel\fR if any \fBs\fRsubstitutions have been made since the most recent reading of an input lineor execution of a \fBt\fR function. If no label is given, branch to the end ofthe script..IP "[2addr]\fBw\fR \fIfile\fR" 4.IX Item "[2addr]w file"The contents of the pattern space are written to the \fIfile\fR..IP "[2addr]\fBx\fR" 4.IX Item "[2addr]x"Swap the contents of the pattern space and the hold space..IP "[2addr]\fBy\fR\fB/\fR\fIstring1\fR\fB/\fR\fIstring2\fR\fB/\fR" 4.IX Item "[2addr]y/string1/string2/"In the pattern space, replace all characters occuring in \fIstring1\fR by thecharacter at the corresponding position in \fIstring2\fR. It is possibleto use any character (other than a backslash or newline) instead of aslash to delimit the strings. Within \fIstring1\fR and \fIstring2\fR, abackslash followed by any character other than a newline is that literalcharacter, and a backslash followed by an `n' is replaced by a newlinecharacter..IP "[1addr]\fB=\fR" 4.IX Item "[1addr]="Prints the current line number on the standard output..IP "[0addr]\fB:\fR [\fIlabel\fR]" 4.IX Item "[0addr]: [label]"The command specifies the position of the \fIlabel\fR. It has no other effect..IP "[2addr]\fB{\fR [\fIcommand\fR]" 4.IX Item "[2addr]{ [command]".PD 0.IP "[0addr]\fB}\fR" 4.IX Item "[0addr]}".PDThese two commands begin and end a command list. The first command maybe given on the same line as the opening \fB{\fR command. The commandswithin the list are jointly selected by the address(es) given on the\&\fB{\fR command (but may still have individual addresses)..IP "[0addr]\fB#\fR [\fIcomment\fR]" 4.IX Item "[0addr]# [comment]"The entire line is ignored (treated as a comment). If, however, the firsttwo characters in the script are `\f(CW\*(C`#n\*(C'\fR', automatic printing of output issuppressed, as if the \fB\-n\fR option were given on the command line..SH "BASIC REGULAR EXPRESSIONS".IX Header "BASIC REGULAR EXPRESSIONS"A \fIBasic Regular Expression\fR (\s-1BRE\s0), as defined in \s-1POSIX\s0 1003.2, consistsof \fIatoms\fR, for matching parts of a string, and \fIbounds\fR, specifyingrepetitions of a preceding atom..Sh "Atoms".IX Subsection "Atoms"The possible atoms of a \s-1BRE\s0 are: \fB.\fR, matching any single character;\&\fB^\fR and \fB$\fR, matching the null string at the beginning or endof a string, respectively; a \fIbracket expressions\fR, enclosedin \fB[\fR and \fB]\fR (see below); and any single character with noother significance (matching that character). A \fB\e\fR before oneof: \fB.\fR, \fB^\fR, \fB$\fR, \fB[\fR, \fB*\fR, \fB\e\fR, matching the characterafter the backslash. A sequence of atoms enclosed in \fB\e(\fR and \fB\e)\fRbecomes an atom and establishes the target for a \fIbackreference\fR,consisting of the substring that actually matches the enclosed atoms.Finally, \fB\e\fR followed by one of the digits \fB0\fR through \fB9\fR is abackreference..PPA \fB^\fR that is not first, or a \fB$\fR that is not last does not havea special significance and need not be preceded by a backslash tobecome literal. The same is true for a \fB]\fR, that does not terminatea bracket expression..PPAn unescaped backslash cannot be last in a \s-1BRE\s0..Sh "Bounds".IX Subsection "Bounds"The \s-1BRE\s0 bounds are: \fB*\fR, specifying 0 or more matches of the precedingatom; \fB\e{\fR\fIcount\fR\fB\e}\fR, specifying that many repetitions;\&\fB\e{\fR\fIminimum\fR\fB,\e}\fR, giving a lower limit; and\&\fB\e{\fR\fIminimum\fR\fB,\fR\fImaximum\fR\fB\e}\fR finally defines a lower and upperbound..PPA bound appearing as the first item in a \s-1BRE\s0 is taken literally..Sh "Bracket Expressions".IX Subsection "Bracket Expressions"A \fIbracket expression\fR is a list of characters, character rangesand character classes enclosed in \fB[\fR and \fB]\fR and matches anysingle character from the represented set of characters..PPA character range is written as two characters separated by \fB\-\fR andrepresents all characters (according to the character collating sequence)that are not less than the first and not greater than the second.(Ranges are very collating-sequence-dependent, and portable programsshould avoid relying on them.).PPA character class is one of the class names.PP.Vb 4\& alnum digit punct\& alpha graph space\& blank lower upper\& cntrl print xdigit.Ve.PPenclosed in \fB[:\fR and \fB:]\fR and represents the set of charactersas defined in \fIctype\fR\|(3)..PPIf the first character after \fB[\fR is \fB^\fR, the sense of matching isinverted..PPTo include a literal `\f(CW\*(C`^\*(C'\fR', place it anywhere else but first. Toinclude a literal '\f(CW\*(C`]\*(C'\fR' place it first or immediately after aninitial \fB^\fR. To include a literal `\f(CW\*(C`\-\*(C'\fR' make it the first (orsecond after \fB^\fR) or last character, or the second endpoint ofa range..PPThe special bracket expression constructs \f(CW\*(C`[[:<:]]\*(C'\fR and \f(CW\*(C`[[:>:]]\*(C'\fR match the null string at the beginning and end of a word respectively.(Note that neither is identical to Perl's `\eb' atom.).Sh "Additional Atoms".IX Subsection "Additional Atoms"Since some sed implementations provide additional regular expressionatoms (not defined in \s-1POSIX\s0 1003.2), \fBpsed\fR is capable of translatingthe following backslash escapes:.ie n .IP "\fB\e<\fR This is the same as ""[[:>:]]""." 4.el .IP "\fB\e<\fR This is the same as \f(CW[[:>:]]\fR." 4.IX Item "< This is the same as [[:>:]].".PD 0.ie n .IP "\fB\e>\fR This is the same as ""[[:<:]]""." 4.el .IP "\fB\e>\fR This is the same as \f(CW[[:<:]]\fR." 4.IX Item "> This is the same as [[:<:]].".ie n .IP "\fB\ew\fR This is an abbreviation for ""[[:alnum:]_]""." 4.el .IP "\fB\ew\fR This is an abbreviation for \f(CW[[:alnum:]_]\fR." 4.IX Item "w This is an abbreviation for [[:alnum:]_].".ie n .IP "\fB\eW\fR This is an abbreviation for ""[^[:alnum:]_]""." 4.el .IP "\fB\eW\fR This is an abbreviation for \f(CW[^[:alnum:]_]\fR." 4.IX Item "W This is an abbreviation for [^[:alnum:]_].".IP "\fB\ey\fR Match the empty string at a word boundary." 4.IX Item "y Match the empty string at a word boundary.".IP "\fB\eB\fR Match the empty string between any two either word or non-word characters." 4.IX Item "B Match the empty string between any two either word or non-word characters.".PD.PPTo enable this feature, the environment variable \s-1PSEDEXTBRE\s0 must be setto a string containing the requested characters, e.g.:\&\f(CW\*(C`PSEDEXTBRE=\*(Aq<>wW\*(Aq\*(C'\fR..SH "ENVIRONMENT".IX Header "ENVIRONMENT"The environment variable \f(CW\*(C`PSEDEXTBRE\*(C'\fR may be set to extend BREs.See \*(L"Additional Atoms\*(R"..SH "DIAGNOSTICS".IX Header "DIAGNOSTICS".IP "ambiguous translation for character `%s' in `y' command" 4.IX Item "ambiguous translation for character `%s' in `y' command"The indicated character appears twice, with different translations..IP "`[' cannot be last in pattern" 4.IX Item "`[' cannot be last in pattern"A `[' in a \s-1BRE\s0 indicates the beginning of a \fIbracket expression\fR..IP "`\e' cannot be last in pattern" 4.IX Item "`' cannot be last in pattern"A `\e' in a \s-1BRE\s0 is used to make the subsequent character literal..IP "`\e' cannot be last in substitution" 4.IX Item "`' cannot be last in substitution"A `\e' in a subsitution string is used to make the subsequent character literal..IP "conflicting flags `%s'" 4.IX Item "conflicting flags `%s'"In an \fBs\fR command, either the `g' flag and an n\-th occurrence flag, ormultiple n\-th occurrence flags are specified. Note that only the digits`1' through `9' are permitted..ie n .IP "duplicate label %s\fR (first defined at \f(CW%s)" 4.el .IP "duplicate label \f(CW%s\fR (first defined at \f(CW%s\fR)" 4.IX Item "duplicate label %s (first defined at %s)".PD 0.IP "excess address(es)" 4.IX Item "excess address(es)".PDThe command has more than the permitted number of addresses..IP "extra characters after command (%s)" 4.IX Item "extra characters after command (%s)".PD 0.IP "illegal option `%s'" 4.IX Item "illegal option `%s'".IP "improper delimiter in s command" 4.IX Item "improper delimiter in s command".PDThe \s-1BRE\s0 and substitution may not be delimited with `\e' or newline..IP "invalid address after `,'" 4.IX Item "invalid address after `,'".PD 0.IP "invalid backreference (%s)" 4.IX Item "invalid backreference (%s)".PDThe specified backreference number exceeds the number of backreferencesin the \s-1BRE\s0..IP "invalid repeat clause `\e{%s\e}'" 4.IX Item "invalid repeat clause `{%s}'"The repeat clause does not contain a valid integer value, or pair ofvalues..IP "malformed regex, 1st address" 4.IX Item "malformed regex, 1st address".PD 0.IP "malformed regex, 2nd address" 4.IX Item "malformed regex, 2nd address".IP "malformed regular expression" 4.IX Item "malformed regular expression".IP "malformed substitution expression" 4.IX Item "malformed substitution expression".IP "malformed `y' command argument" 4.IX Item "malformed `y' command argument".PDThe first or second string of a \fBy\fR command is syntactically incorrect..IP "maximum less than minimum in `\e{%s\e}'" 4.IX Item "maximum less than minimum in `{%s}'".PD 0.IP "no script command given" 4.IX Item "no script command given".PDThere must be at least one \fB\-e\fR or one \fB\-f\fR option specifying ascript or script file..IP "`\e' not valid as delimiter in `y' command" 4.IX Item "`' not valid as delimiter in `y' command".PD 0.IP "option \-e requires an argument" 4.IX Item "option -e requires an argument".IP "option \-f requires an argument" 4.IX Item "option -f requires an argument".IP "`s' command requires argument" 4.IX Item "`s' command requires argument".IP "start of unterminated `{'" 4.IX Item "start of unterminated `{'".IP "string lengths in `y' command differ" 4.IX Item "string lengths in `y' command differ".PDThe translation table strings in a \fBy\fR command must have equal lengths..IP "undefined label `%s'" 4.IX Item "undefined label `%s'".PD 0.IP "unexpected `}'" 4.IX Item "unexpected `}'".PDA \fB}\fR command without a preceding \fB{\fR command was encountered..IP "unexpected end of script" 4.IX Item "unexpected end of script"The end of the script was reached although a text line after a\&\fBa\fR, \fBc\fR or \fBi\fR command indicated another line..IP "unknown command `%s'" 4.IX Item "unknown command `%s'".PD 0.IP "unterminated `['" 4.IX Item "unterminated `['".PDA \s-1BRE\s0 contains an unterminated bracket expression..IP "unterminated `\e('" 4.IX Item "unterminated `('"A \s-1BRE\s0 contains an unterminated backreference..IP "`\e{' without closing `\e}'" 4.IX Item "`{' without closing `}'"A \s-1BRE\s0 contains an unterminated bounds specification..IP "`\e)' without preceding `\e('" 4.IX Item "`)' without preceding `('".PD 0.IP "`y' command requires argument" 4.IX Item "`y' command requires argument".PD.SH "EXAMPLE".IX Header "EXAMPLE"The basic material for the preceding section was generated by runningthe sed script.PP.Vb 10\& #no autoprint\& s/^.*Warn( *"\e([^"]*\e)".*$/\e1/\& t process\& b\& :process\& s/$!/%s/g\& s/$[_[:alnum:]]\e{1,\e}/%s/g\& s/\e\e\e\e/\e\e/g\& s/^/=item /\& p.Ve.PPon the program's own text, and piping the output into \f(CW\*(C`sort \-u\*(C'\fR..SH "SED SCRIPT TRANSLATION".IX Header "SED SCRIPT TRANSLATION"If this program is invoked with the name \fIs2p\fR it will act as ased-to-Perl translator. After option processing (all otherarguments are ignored), a Perl program is printed on standardoutput, which will process the input stream (as read from allarguments) in the way defined by the sed script and the option settingused for the translation..SH "SEE ALSO".IX Header "SEE ALSO"\&\fIperl\fR\|(1), \fIre_format\fR\|(7).SH "BUGS".IX Header "BUGS"The \fBl\fR command will show escape characters (\s-1ESC\s0) as `\f(CW\*(C`\ee\*(C'\fR', buta vertical tab (\s-1VT\s0) in octal..PPTrailing spaces are truncated from labels in \fB:\fR, \fBt\fR and \fBb\fR commands..PPThe meaning of an empty regular expression (`\f(CW\*(C`//\*(C'\fR'), as defined by \fBsed\fR,is \*(L"the last pattern used, at run time\*(R". This deviates from the Perlinterpretation, which will re-use the \*(L"last last successfully executedregular expression\*(R". Since keeping track of pattern usage would createterribly cluttered code, and differences would only appear in obscurecontext (where other \fBsed\fR implementations appear to deviate, too),the Perl semantics was adopted. Note that common usage of this feature,such as in \f(CW\*(C`/abc/s//xyz/\*(C'\fR, will work as expected..PPCollating elements (of bracket expressions in BREs) are not implemented..SH "STANDARDS".IX Header "STANDARDS"This \fBsed\fR implementation conforms to the \s-1IEEE\s0 Std1003.2\-1992 (\*(L"\s-1POSIX\s0.2\*(R")definition of \fBsed\fR, and is compatible with the \fIOpenBSD\fRimplementation, except where otherwise noted (see \*(L"\s-1BUGS\s0\*(R")..SH "AUTHOR".IX Header "AUTHOR"This Perl implementation of \fIsed\fR was written by Wolfgang Laun,\&\fIWolfgang.Laun@alcatel.at\fR..SH "COPYRIGHT and LICENSE".IX Header "COPYRIGHT and LICENSE"This program is free and open software. You may use, modify,distribute, and sell this program (and any modified variants) in anyway you wish, provided you do not restrict others from doing the same.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -