?? sed
字號:
.hw de-limit.hw de-limit-ing.RP....TM 78-1270-1 39199 39199-11.ND August 15, 1978.TLSED \(em A Non-interactive Text Editor.AU "MH 2C-555" 3302Lee E. McMahon.AI.MH.OKContext searchEditing.AB.ulSedis a non-interactive context editorthat runs on the.UXoperating system..ulSedisdesigned to be especially useful inthree cases:.in +1i.LP.ti -.5i1)To edit files too large for comfortableinteractive editing;.ti -.5i2)To edit any size file when the sequenceof editing commands is too complicated to be comfortablytyped in interactive mode..ti -.5i3)To perform multiple `global' editing functionsefficiently in one pass through the input..in -1i.LPThis memorandum constitutes a manual for users of.ulsed..AE.CS 10 0 10 0 0 1.SHIntroduction.LP.ulSedis a non-interactive context editor designed to be especially useful inthree cases:.in +1i.LP.ti -.5i1)To edit files too large for comfortableinteractive editing;.ti -.5i2)To edit any size file when the sequenceof editing commands is too complicated to be comfortablytyped in interactive mode;.ti -.5i3)To perform multiple `global' editing functionsefficiently in one pass through the input..in -1i.LPSince only a few lines of the input reside in coreat one time, and no temporary files are used,the effective size of file that can be edited is limited onlyby the requirement that the input and output fit simultaneouslyinto available secondary storage..LPComplicated editing scripts can be created separately and givento .ulsedas a command file.For complex edits, this saves considerable typing, and itsattendant errors..ulSedrunning from a command file is much more efficient than any interactiveeditor known to the author, even if that editorcan be driven by a pre-written script..LPThe principal loss of functions compared to an interactive editorare lack of relative addressing (because of the line-at-a-timeoperation), and lack of immediate verification that a command hasdone what was intended..LP.ulSedis a lineal descendant of the UNIX editor,.uled.Because of the differences between interactive and non-interactiveoperation, considerable changes have been made between.uledand.ulsed;even confirmed users of.uledwill frequently be surprised (and probably chagrined),if they rashly use .ulsedwithout reading Sections 2 and 3 of this document.The most striking family resemblance between the twoeditors is in the class of patterns (`regular expressions') theyrecognize;the code for matching patterns is copied almostverbatim from the code for.uled,and the description of regular expressions in Section 2is copied almost verbatim from the UNIX Programmer'sManual[1]. (Both code and description were written by DennisM. Ritchie.).LP.SH1. Overall Operation.LP.ulSedby default copies the standard input to the standard output,perhaps performing one or more editing commands on eachline before writing it to the output.This behavior may be modified by flags on the command line;see Section 1.1 below..LPThe general format of an editing command is:.LP.in +1i[address1,address2][function][arguments].LP.in -1iOne or both addresses may be omitted; the format of addresses isgiven in Section 2.Any number of blanks or tabs may separate the addressesfrom the function.The function must be present; the available commands are discussedin Section 3.The arguments may be required or optional, according to which functionis given; again, they are discussed in Section 3 under each individualfunction..LPTab characters and spaces at the beginning of lines are ignored..LP.SH1.1. Command-line Flags.LPThree flags are recognized on the command line:.in +1i.ti -.5i.B-n:.Rtells.ulsednot to copy all lines, but only those specified by.ulpfunctions or.ulpflags after .ulsfunctions (see Section 3.3);.ti -.5i.B-e:.Rtells.ulsedto take the next argument as an editing command;.ti -.5i.B-f:.Rtells.ulsedto take the next argument as a file name;the file should contain editing commands, one to a line..in -1i.SH1.2. Order of Application of Editing Commands.LPBefore any editing is done (in fact, before any input file iseven opened), all the editing commands are compiled intoa form which will be moderately efficient duringthe execution phase (when the commands are actually applied tolines of the input file).The commands are compiled in the order in which they areencountered; this is generally the order in which they willbe attempted at execution time.The commands are applied one at a time; the input to each commandis the output of all preceding commands..LPThe default linear order of application of editing commands canbe changed by the flow-of-control commands,.ultand.ulb(see Section 3).Even when the order of application is changedby these commands, it is still true that the input line to anycommand is the output of any previously applied command..SH1.3. Pattern-space.LPThe range of pattern matches is called the pattern space.Ordinarily, the pattern space is one line of the input text,but more than one line can be read into the pattern spaceby using the.ulNcommand (Section 3.6.)..LP.SH1.4. Examples.LPExamples are scattered throughout the text.Except where otherwise noted,the examples all assume the following input text:.LP.in +.5i.nfIn Xanadu did Kubla KhanA stately pleasure dome decree:Where Alph, the sacred river, ranThrough caverns measureless to manDown to a sunless sea..in -.5i.fi.LP(In no case is the output of the .ulsedcommands to be considered an improvementon Coleridge.).LP.SHExample:.LPThe command.in +.5i.LP2q.in -.5i.LPwill quit after copying the first two lines of the input.The output will be:.LP.in +.5i.nfIn Xanadu did Kubla KhanA stately pleasure dome decree:.in -.5i.fi.LP.SH2. ADDRESSES: Selecting lines for editing.LPLines in the input file(s) to which editing commands areto be applied can be selected by addresses.Addresses may be either line numbers or context addresses..LPThe application of a group of commands can be controlled byone address (or address-pair) by groupingthe commands with curly braces (`{ }')(Sec. 3.6.)..SH2.1. Line-number Addresses.LPA line number is a decimal integer.As each line is read from the input, a line-number counteris incremented;a line-number address matches (selects) the inputline which causes the internal counter to equal theaddress line-number.The counter runs cumulatively through multiple input files;it is not reset when a new input file is opened..LPAs a special case, the character$matches the last line of the last input file..SH2.2. Context Addresses.LPA context address is a pattern (`regular expression') enclosed in slashes (`/').The regular expressions recognized by.ulsedare constructed as follows:.in +1i.LP.ti -.5i1)An ordinary character (not one of those discussed below)is a regular expression, and matches that character..LP.ti -.5i2)A circumflex `^' at the beginning of a regular expressionmatches the null character at the beginning of a line..ti -.5i3)A dollar-sign `$' at the end of a regular expressionmatches the null character at the end of a line..ti -.5i4)The characters `\en' match an imbedded newline character,but not the newline at the end of the pattern space..ti -.5i5)A period `.' matches any character except the terminal newlineof the pattern space..ti -.5i6)A regular expression followed by an asterisk `*' matches anynumber (including 0) of adjacent occurrences of the regularexpression it follows..ti -.5i7)A string of characters in square brackets `[ ]' matches any characterin the string, and no others.If, however, the first character of the string is circumflex `^',the regular expression matches any character.ulexceptthe characters in the string and the terminal newline of the pattern space..ti -.5i8)A concatenation of regular expressions is a regular expressionwhich matches the concatenation of strings matched by thecomponents of the regular expression..ti -.5i9)A regular expression between the sequences `\e(' and `\e)' isidentical in effect to the unadorned regular expression, but hasside-effects which are described under the.ulscommand below and specification 10) immediately below..ti -.5i10)The expression.ul`\|\ed'means the same string of characters matchedby an expression enclosed in `\e(' and `\e)'earlier in the same pattern.Here.uldis a single digit;the string specified is that beginning with the\fId\|\fRthoccurrence of `\e(' counting from the left.For example, the expression`^\e(.*\e)\e1' matches a line beginning withtwo repeated occurrences of the same string..ti -.5i11)The null regular expression standing alone (e.g., `//') isequivalent to the last regular expression compiled..in -1i.LPTo use one of the special characters (^ $ . * [ ] \e /) as a literal(to match an occurrence of itself in the input), precede thespecial character by a backslash `\e'..LPFor a context address to `match' the input requires thatthe whole pattern within the address match someportion of the pattern space..SH2.3. Number of Addresses.LPThe commands in the next section can have 0, 1, or 2 addresses.Under each command the maximum number of allowed addresses isgiven.For a command to have more addresses than the maximum allowedis considered an error..LPIf a command has no addresses, it is applied to every linein the input..LPIf a command has one address, it is applied to alllines which match that address..LPIf a command has two addresses, it is applied to the firstline which matches the first address, and to all subsequent linesuntil (and including) the first subsequent line which matchesthe second address.Then an attempt is made on subsequent lines to again match the firstaddress, and the process is repeated..LPTwo addresses are separated by a comma..SHExamples:.LP.nf.in +.5i.ta 1i 2i/an/ matches lines 1, 3, 4 in our sample text/an.*an/ matches line 1/^an/ matches no lines/./ matches all lines/\e./ matches line 5/r*an/ matches lines 1,3, 4 (number = zero!)/\e(an\e).*\e1/ matches line 1.fi.in 0.LP.SH3. FUNCTIONS.LPAll functions are named by a single character.In the following summary, the maximum number of allowable addressesis given enclosed in parentheses, then the single characterfunction name, possible arguments enclosed in angles (< >),an expanded English translation of the single-character name,and finally a description of what each function does.The angles around the arguments are.ulnotpart of the argument, and should not be typedin actual editing commands..SH3.1. Whole-line Oriented Functions.LP.in +1i.ti -.5i(2)d -- delete lines.if t .sp .5The.uldfunction deletes from the file (does not write to the output)all those lines matched by its address(es)..if t .sp .5It also has the side effect that no further commands are attemptedon the corpse of a deleted line;as soon as the.uldfunction is executed, a new line is read from the input, andthe list of editing commands is re-started from the beginningon the new line..ti -.5i.if t .sp .5(2)n -- next line.if t .sp .5The.ulnfunction reads the next line from the input, replacingthe current line.The current line is written to the output if it shouldbe.The list of editing commands is continued following the .ulncommand..if t .sp .5.nf.in -.5i(1)a\e<text> -- append lines.in +.5i.fi.if t .sp .5The.ulafunction causes the argument <text> to be written to theoutput after the line matched by its address.The.ulacommand is inherently multi-line;.ulamust appear at the end of a line, and <text> may containany number of lines.To preserve the one-command-to-a-line fiction,the interior newlines must be hidden by abackslash character (`\e') immediately preceding thenewline.The <text> argument is terminated by the first unhiddennewline (the first one not immediately precededby backslash)..if t .sp .5Once an.ulafunction is successfully executed, <text> will bewritten to the output regardless of what later commands do tothe line which triggered it.The triggering line may be deleted entirely; <text> will still be written to the output..if t .sp .5The <text> is not scanned for address matches, and no editingcommands are attempted on it.It does not cause any change in the line-number counter..if t .sp .5.nf.in -.5i(1)i\e<text> -- insert lines.in +.5i.fi.if t .sp .5The.ulifunction behaves identically to the.ulafunction, except that <text> is written to the output.ulbeforethe matched line.All other comments about the.ulafunction apply to the.ulifunction as well..if t .sp .5.nf.in -.5i(2)c\e<text> -- change lines.in +.5i.fi.if t .sp .5The.ulcfunction deletes the lines selected by its address(es),and replaces them with the lines in <text>.Like.ulaand.uli,.ulcmust be followed by a newline hidden by a backslash;and interior new lines in <text> must be hidden bybackslashes..if t .sp .5The.ulccommand may have two addresses, and therefore select a rangeof lines.If it does, all the lines in the range are deleted, but onlyone copy of <text> is written to the output,.ulnotone copy per line deleted.As with.ulaand.uli,<text> is not scanned for address matches, and noediting commands are attempted on it.It does not change the line-number counter..if t .sp .5After a line has been deleted by a.ulcfunction, no further commands are attempted on the corpse..if t .sp .5If text is appended after a line by.ulaor.ulrfunctions, and the line is subsequently changed, the textinserted by the.ulcfunction will be placed.ulbeforethe text of the.ulaor.ulrfunctions.(The.ulrfunction is described in Section 3.4.).if t .sp .5.in -1i.ulNote:Within the text put in the output by these functions,leading blanks and tabs will disappear, as always in .ulsedcommands.To get leading blanks and tabs into the output, precede the firstdesired blank or tab by a backslash; the backslash will not
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -