sed.1

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 342 行

1
342
字号
.\" SCCSID: @(#)sed.1	8.2	11/30/90.TH sed 1 .SH Namesed \- stream text editor.SH Syntax.B sed[\fB\-n\fR] [\fB\-e\fI script\fR\|] [\fB\-f\fI sfile\fR\|] [\|\fIfile...\fR\|].SH Description.NXR "editors" "sed".NXR "stream text editor".NXR "sed command"The.PN sedcommand copies the named.I files(standard input default) to the standard output,edited according to a script of commands.The.B \-foption causes the script to be taken from file.IR sfile ;these options accumulate.If there is just one.B \-eoption and no.BR \-f 's,the flag.B \-emay be omitted.The.B \-noption suppresses the default output; inclusion in the script of acomment command of the form.PN #nalso suppresses the default output.  (See the description of the `#'command.).PPA script consists of editing commands of the following form:.IP[address [, address] ] function [arguments].PPNominally, there is one command per line; but commands can beconcatenated on a line by being separated with semicolons.Pn ( ; )..PPIn normal operation.PN sedcyclically copies a line of input into a.I pattern space(unless there is something left aftera `D' command),applies in sequenceall commands whose.I addressesselect that pattern space,and at the end of the script copies the pattern spaceto the standard output (except under.BR \-n )and deletes the pattern space..PPAn.I addressis either a decimal number that countsinput lines cumulatively across files, a `$' thataddresses the last line of input, or a context address,`/regular expression/', in the style of ed(1) modified thus:.RS 3.IP \(bu 5In a context address, the construction \\\fI?regular expression?\fP,where \fI?\fP is any character, is identical to \/\fIregular expression\fP\/. Note that in the context address \\\fIxabc\fP\\\fIxdefx\fP, the second .I xstands for itself, so that the regular expression is .IR abcxdef ..IP \(buThe escape sequence `\en' matches anew line embedded in the pattern space..IP \(buA command line with no addresses selects every pattern space..IP \(buA command line withone address selects each pattern space that matches the address..IP \(buA command line withtwo addresses selects the inclusive range from the firstpattern space that matches the first address throughthe next pattern space that matches the second.(If the second address is a number less than or equalto the line number first selected, only oneline is selected.)Thereafter the process is repeated, looking again for thefirst address..RE.PPEditing commands can be applied only to non-selected patternspaces by use of the negation function `!' (below)..PPIn the following list of functions the maximum number of permissible addressesfor each function is indicated in parentheses..PPAn argument denoted.I textconsists of one or more lines,all but the last of which end with `\e' to hide thenew line.Backslashes in text are treated like backslashesin the replacement string of an `s' command,and may be used to protect initial blanks and tabsagainst the stripping that is done on every script line..PPAn argument denoted.I rfileor.I wfilemust terminate the commandline and must be preceded by exactly one blank.Each.I wfileis created before processing begins.There can be at most 10 distinct.I wfilearguments..TP 8(1)\|a\e.br.ns.TP 8.I text.brAppend.Place.I texton the output beforereading the next input line..TP 8.RI (2)\|b " label"Branch to the `:' command bearing the.IR label .If.I labelis empty, branch to the end of the script..TP 8(2)\|c\e.br.ns.TP 8.I text.brChange.Delete the pattern space.With 0 or 1 address or at the end of a 2-address range, place.I texton the output.Start the next cycle..TP 8(2)\|dDelete the pattern space.Start the next cycle..TP 8(2)\|DDelete the initial segment of the pattern space through the first new line.Start the next cycle..TP 8(2)\|gReplace the contents of the pattern spaceby the contents of the hold space..TP 8(2)\|GAppend the contents of the hold space to the pattern space..TP 8(2)\|hReplace the contents of the hold space bythe contents of the pattern space..TP 8(2)\|HAppend the contents of the pattern space to the hold space..TP 8(1)\|i\e.br.ns.TP 8.I text.brInsert.Place.I texton the standard output..TP 8(2)\|nCopy the pattern space to the standard output.Replace the pattern space with the next line of input..TP 8(2)\|NAppend the next line of input to the pattern spacewith an embedded new line.(The current line number changes.).TP 8(2)\|pPrint.Copy the pattern space to the standard output..TP 8(2)\|PCopy the initial segment of the pattern space throughthe first new line to the standard output..TP 8(1)\|qQuit.Branch to the end of the script.Do not start a new cycle..TP 8.RI (2)\|r " rfile"Read the contents of.IR rfile .Place them on the output before readingthe next input line..TP 8.RI (2)\|s /regular\ expression/replacement/flagsSubstitute the.I replacementstring for instances of the.I regular expressionin the pattern space.Any character may be used instead of `/'.For a more complete description see.MS ed 1 .The.I flagsis zero or more of.RS.TP 8gGlobal.Substitute for all nonoverlapping instances of the.I regular expressionrather than just thefirst one..TP 8pPrint the pattern space if a replacement was made..TP 8.RI w " wfile"Write.Append the pattern space to.I wfileif a replacementwas made..RE.TP 8.RI (2)\|t " label"Test.Branch to the `:' command bearing the.I labelif anysubstitutions have been made since the most recentreading of an input line or execution of a `t'.If .I labelis empty, branch to the end of the script..TP 8.RI (2)\|w " wfile"Write.Append the pattern space to.IR wfile ..TP 8.RI (2)\|xExchange the contents of the pattern and hold spaces..TP 8.RI (2)\|y /string1/string2/Transform.Replace all occurrences of characters in.I string1with the corresponding character in.I string2.The lengths of.Istring1and.I string2must be equal..TP 8.RI (2)! " function"Don't.Apply the.I function(or group, if.I functionis `{') only to lines.I notselected by the address(es)..TP 8.RI (0)\|: " label"This command does nothing; it bears a.I labelfor `b' and `t' commands to branch to..TP 8(1)\|=Place the current line number on the standard output as a line..TP 8(2)\|{Execute the following commands through a matching `}'only when the pattern space is selected..TP 8(0)\|An empty command is ignored..TP 8(0)\|#With one exception, any line whose first nonblank character is a numbersign is a comment and is ignored.  The exception is that if the first suchline encountered contains only the number sign followed by the letter `n'.Pn ( #n ),the default output is suppressed as if the.B \-noption were in force..SH Options.IP "\-e\fI 'command;command...'\fP" 8Uses.I command;command...as the editing script.  If no.B \-foption is given, the.B \-ekeyword can be omitted.  For example, the following two command arefunctionally identical:.EX% \f(CBsed -e 's/DIGITAL/Digital/g' summary > summary.out\f(CB% \f(CBsed 's/DIGITAL/Digital/g' summary > summary.out\f(CB.EE.IP "\-f\fI sfile\fP"Uses specified file as input file of commands to be executed.  Can beused with.B \-eoption to apply both explicit commands and a separate script file..IP \-n\fPSuppresses all normal output, writing only lines explicitly writtenby the `p' or `P' commands or by an `s' command with the `p' flag..SH See Alsoawk(1), ed(1), grep(1), lex(1)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?