147839Sbostic.\" Copyright (c) 1980, 1991 The Regents of the University of California. 247839Sbostic.\" All rights reserved. 319660Smckusick.\" 447839Sbostic.\" %sccs.include.proprietary.man% 543083Scael.\" 6*67457Smckusick.\" @(#)ed.1 6.9.1.1 (Berkeley) 06/27/94 747839Sbostic.\" 843083Scael.Dd 943083Scael.Dt ED 1 1043083Scael.Os ATT 7th 1143083Scael.Sh NAME 1257011Scael.Nm \&ed 1343083Scael.Nd text editor 1443083Scael.Sh SYNOPSIS 1557011Scael.Nm \&ed 1643083Scael.Op Fl 1743083Scael.Op Ar file 1843083Scael.Sh DESCRIPTION 1957011Scael.Nm \&Ed 2057011Scaelonce was 2157011Scaelthe standard text editor in the early days of 2257011Scael.Ux . 2357011ScaelWhile its life as a line editor is dated, 2457011Scael.Nm \&ed 2557011Scaelstill resides on systems produced 2657011Scaelby a variety of vendors for good reason. 2757011ScaelBecause of its 2857011Scaelsmall size and simplicity, 2965227Smckusick.Nm \&ed 3057011Scaelis found on the root partition 3157011Scael.Pq Pa /bin/ed 3257011Scaelfor emergency editing when normal system 3357011Scaelreboots fail or single user tasks 3457011Scaelare performed and 3557011Scael.Pa /usr 3657011Scaelis not mounted. 3757011Scael.Nm \&Ed 3857011Scaelis also useful for script editing tasks, 3957011Scaeland although there is nothing which can 4057011Scaelbe done by 4157011Scael.Nm \&ed 4257011Scaelthat cannot be performed by 4357011Scael.Xr sed 1 , 4457011Scael.Xr ex 1 4557011Scaelor 4657011Scael.Em Gnu Emacs , 4757011Scael.Nm \&ed 4857011Scaelremains the simplest and easiest to use. 4943083Scael.Pp 5019660SmckusickIf a 5143083Scael.Ar file 5219660Smckusickargument is given, 5357011Scael.Nm \&ed 5419660Smckusicksimulates an 5557011Scael.Cm \&e 5643083Scaelcommand (see below) on the named file; that is to say, 5719660Smckusickthe file is read into 5857011Scael.Nm \&ed Ns 's 5919660Smckusickbuffer so that it can be edited. 6057011Scael.Pp 6157011ScaelAvailable options: 6257011Scael.Bl -tag -width Ds 6357011Scael.It Fl 6443083ScaelSuppresses the printing 6519660Smckusickof explanatory output 6619660Smckusickand should be used 6719660Smckusickwhen the standard input is 6819660Smckusickan editor script. 6957011Scael.El 7043083Scael.Pp 7157011Scael.Nm \&Ed 7219660Smckusickoperates on a copy of any file it is editing; changes made 7319660Smckusickin the copy have no effect on the file until a 7457011Scael.Cm \&w 7543083Scael(write) command is given. 7619660SmckusickThe copy of the text being edited resides 7743083Scaelin a temporary file called the 7843083Scael.Ar buffer . 7943083Scael.Pp 8019660SmckusickCommands to 8157011Scael.Nm \&ed 8219660Smckusickhave a simple and regular structure: zero or 8319660Smckusickmore 8457011Scael.Ad addresses 8519660Smckusickfollowed by a single character 8657011Scael.Cm command , 8719660Smckusickpossibly 8819660Smckusickfollowed by parameters to the command. 8919660SmckusickThese addresses specify one or more lines in the buffer. 9019660SmckusickMissing addresses are supplied by default. 9143083Scael.Pp 9219660SmckusickIn general, only one command may appear on a line. 9343083ScaelCertain commands allow the 9419660Smckusickaddition of text to the buffer. 9519660SmckusickWhile 9657011Scael.Nm \&ed 9719660Smckusickis accepting text, it is said 9819660Smckusickto be in 9943083Scael.Ar input mode . 10019660SmckusickIn this mode, no commands are recognized; 10119660Smckusickall input is merely collected. 10243083ScaelInput mode is left by typing a period 10357011Scael.Sq Ad \&. 10443083Scaelalone at the 10519660Smckusickbeginning of a line. 10643083Scael.Pp 10757011Scael.Nm \&Ed 10819660Smckusicksupports a limited form of 10943083Scael.Ar regular expression 11019660Smckusicknotation. 11119660SmckusickA regular expression specifies 11219660Smckusicka set of strings of characters. 11319660SmckusickA member of this set of strings is said to be 11443083Scael.Ar matched 11519660Smckusickby the regular expression. 11619660SmckusickIn the following specification for regular expressions 11719660Smckusickthe word `character' means any character but newline. 11857011Scael.Bl -enum 11957011Scael.It 12019660SmckusickAny character except a special character 12119660Smckusickmatches itself. 12219660SmckusickSpecial characters are 12319660Smckusickthe regular expression delimiter plus 12457011Scael.Ql \e\&[. 12543083Scaeland sometimes 12657011Scael.Ql ^*$ . 12757011Scael.It 12819660SmckusickA 12957011Scael.Sq Ql \&. 13019660Smckusickmatches any character. 13157011Scael.It 13243083ScaelA 13357011Scael.Ql \e 13443083Scaelfollowed by any character except a digit or 13543083Scael.Li (\) 13643083Scaelmatches that character. 13757011Scael.It 13819660SmckusickA nonempty string 13957011Scael.Ar \&s 14057011Scaelbracketed 14157011Scael.Bq Ar \&s 14257011Scael(or 14357011Scael.Bq Ar \&^s ) 14419660Smckusickmatches any character in (or not in) 14557011Scael.Ar \&s. 14643083ScaelIn 14757011Scael.Ar \&s, 14857011Scael.Ql \e 14943083Scaelhas no special meaning, and 15043083Scaelmay only appear as 15119660Smckusickthe first letter. 15243083ScaelA substring 15357011Scael.Ar \&a\-b , 15419660Smckusickwith 15557011Scael.Ar \&a 15619660Smckusickand 15757011Scael.Ar \&b 15857011Scaelin ascending 15957011Scael.Tn ASCII 16057011Scaelorder, stands for the inclusive 16157011Scaelrange of 16257011Scael.Tn ASCII 16357011Scaelcharacters. 16457011Scael.It 16557011ScaelA regular expression of form 1\-4 followed by 16657011Scael.Ql \&* 16757011Scaelmatches a sequence of 16819660Smckusick0 or more matches of the regular expression. 16957011Scael.It 17019660SmckusickA regular expression, 17157011Scael.Ar \&x , 17243083Scaelof form 1\-8, bracketed 17357011Scael.No \e( Ar \&x Ns \e) 17419660Smckusickmatches what 17557011Scael.Ar \&x 17619660Smckusickmatches. 17757011Scael.It 17843083ScaelA \e followed by a digit 17957011Scael.Ar \&n 18019660Smckusickmatches a copy of the string that the 18119660Smckusickbracketed regular expression beginning with the 18257011Scael.Ar \&n Ns \&th 18357011Scael.No \e( 18443083Scaelmatched. 18557011Scael.It 18643083ScaelA regular expression of form 1\-8, 18757011Scael.Ar \&x , 18843083Scaelfollowed by a regular expression of form 1\-7, 18965227Smckusick.Ar \&y, 19019660Smckusickmatches a match for 19157011Scael.Ar \&x 19219660Smckusickfollowed by a match for 19357011Scael.Ar \&y , 19419660Smckusickwith the 19557011Scael.Ar \&x 19619660Smckusickmatch being as long as possible while still permitting a 19757011Scael.Ar \&y 19819660Smckusickmatch. 19957011Scael.It 20043083ScaelA regular expression of form 1\-8 preceded by 20143083Scael.Sq Li ^ 20243083Scael(or followed by 20343083Scael.Sq Li $ ) , 20443083Scaelis constrained to matches that 20519660Smckusickbegin at the left (or end at the right) end of a line. 20657011Scael.It 20743083ScaelA regular expression of form 1\-9 picks out the 20819660Smckusicklongest among the leftmost matches in a line. 20957011Scael.It 21019660SmckusickAn empty regular expression stands for a copy of the 21119660Smckusicklast regular expression encountered. 21257011Scael.El 21343083Scael.Pp 21419660SmckusickRegular expressions are used in addresses to specify 21519660Smckusicklines and in one command 21619660Smckusick(see 21757011Scael.Ar \&s 21843083Scaelbelow) 21919660Smckusickto specify a portion of a line which is to be replaced. 22019660SmckusickIf it is desired to use one of 22119660Smckusickthe regular expression metacharacters as an ordinary 22243083Scaelcharacter, that character may be preceded by 22343083Scael.Sq Li \e . 22419660SmckusickThis also applies to the character bounding the regular 22543083Scaelexpression (often 22643083Scael.Sq Li \&/ ) 22743083Scaeland to 22843083Scael.Sq Li \e 22943083Scaelitself. 23043083Scael.Pp 23119660SmckusickTo understand addressing in 23257011Scael.Nm \&ed 23319660Smckusickit is necessary to know that at any time there is a 23443083Scael.Ar current line. 23519660SmckusickGenerally speaking, the current line is 23619660Smckusickthe last line affected by a command; however, 23719660Smckusickthe exact effect on the current line 23819660Smckusickis discussed under the description of 23919660Smckusickthe command. 24019660SmckusickAddresses are constructed as follows. 24157011Scael.Bl -enum 24257011Scael.It 24343083ScaelThe character 24457011Scael.Sq Ad \&. 24543083Scaeladdresses the current line. 24657011Scael.It 24743083ScaelThe character 24857011Scael.Sq Ad \&$ 24943083Scaeladdresses the last line of the buffer. 25057011Scael.It 25119660SmckusickA decimal number 25257011Scael.Ar \&n 25319660Smckusickaddresses the 25457011Scael.Ar \&n Ns \&th 25519660Smckusickline of the buffer. 25657011Scael.It 25757011Scael.Sq \(fm Ns Ar \&x 25843083Scaeladdresses the line marked with the name 25957011Scael.Ar \&x , 26019660Smckusickwhich must be a lower-case letter. 26119660SmckusickLines are marked with the 26257011Scael.Ar \&k 26319660Smckusickcommand described below. 26457011Scael.It 26543083ScaelA regular expression enclosed in slashes 26657011Scael.Ql \&/ 26743083Scaeladdresses 26819660Smckusickthe line found by searching forward from the current line 26919660Smckusickand stopping at the first line containing a 27019660Smckusickstring that matches the regular expression. 27119660SmckusickIf necessary the search wraps around to the beginning of the 27219660Smckusickbuffer. 27357011Scael.It 27457011ScaelA regular expression enclosed in queries 27557011Scael.Ql ? 27643083Scaeladdresses 27719660Smckusickthe line found by searching backward from the current line 27819660Smckusickand stopping at the first line containing 27919660Smckusicka string that matches the regular expression. 28019660SmckusickIf necessary 28119660Smckusickthe search wraps around to the end of the buffer. 28257011Scael.It 28343083ScaelAn address followed by a plus sign 28457011Scael.Ql \&+ 28543083Scaelor a minus sign 28657011Scael.Ql \- 28743083Scaelfollowed by a decimal number specifies that address plus 28843083Scael(resp. minus) the indicated number of lines. 28919660SmckusickThe plus sign may be omitted. 29057011Scael.It 29143083ScaelIf an address begins with 29257011Scael.Ql \&+ 29343083Scaelor 29457011Scael.Ql \- 29519660Smckusickthe addition or subtraction is taken with respect to the current line; 29643083Scaele.g. 29757011Scael.Ql \-5 29843083Scaelis understood to mean 29957011Scael.Ql .\-5 . 30057011Scael.It 30143083ScaelIf an address ends with 30257011Scael.Ql \&+ 30357011Scaelor 30457011Scael.Ql \&\- 30519660Smckusickthen 1 is added (resp. subtracted). 30619660SmckusickAs a consequence of this rule and rule 8, 30743083Scaelthe address 30857011Scael.Ql \&\- 30943083Scaelrefers to the line before the current line. 31019660SmckusickMoreover, 31119660Smckusicktrailing 31257011Scael.Ql \&+ 31343083Scaeland 31457011Scael.Ql \&\- 31543083Scaelcharacters 31643083Scaelhave cumulative effect, so 31757011Scael.Ql \&\-\- 31843083Scaelrefers to the current 31919660Smckusickline less 2. 32057011Scael.It 32119660SmckusickTo maintain compatibility with earlier versions of the editor, 32243083Scaelthe character 32357011Scael.Ql \&^ 32443083Scaelin addresses is 32543083Scaelequivalent to 32657011Scael.Ql \&\- 32757011Scael.El 32843083Scael.Pp 32919660SmckusickCommands may require zero, one, or two addresses. 33019660SmckusickCommands which require no addresses regard the presence 33119660Smckusickof an address as an error. 33219660SmckusickCommands which accept one or two addresses 33365227Smckusickassume default addresses when insufficient ones are given. 33419660SmckusickIf more addresses are given than such a command requires, 33543083Scaelthe last one or two (depending on what is accepted) are used. 33643083Scael.Pp 33719660SmckusickAddresses are separated from each other typically by a comma 33865227Smckusick.Ql \&, . 33919660SmckusickThey may also be separated by a semicolon 34065227Smckusick.Ql \&; . 34157011ScaelIn this case the current line 34257011Scael.Ql \&. 34343083Scaelis set to 34419660Smckusickthe previous address before the next address is interpreted. 34519660SmckusickThis feature can be used to determine the starting 34643083Scaelline for forward and backward searches 34757011Scael.Pf ( Ql \&/ , 34865227Smckusick.Ql \&? ). 34919660SmckusickThe second address of any two-address sequence 35019660Smckusickmust correspond to a line following the line corresponding to the first address. 35143083ScaelThe special form 35257011Scael.Ql \&% 35343083Scaelis an abbreviation for the address pair 35457011Scael.Ql \&1,$ . 35543083Scael.Pp 35619660SmckusickIn the following list of 35757011Scael.Nm \&ed 35819660Smckusickcommands, the default addresses 35919660Smckusickare shown in parentheses. 36019660SmckusickThe parentheses are not part of 36119660Smckusickthe address, but are used to show that the given addresses are 36219660Smckusickthe default. 36343083Scael.Pp 36419660SmckusickAs mentioned, it is generally illegal for more than one 36519660Smckusickcommand to appear on a line. 36657011ScaelHowever, most commands may be suffixed by 36757011Scael.Ql \&p 36857011Scaelor by 36957011Scael.Ql \&l , 37057011Scaelin which case 37119660Smckusickthe current line is either 37219660Smckusickprinted or listed respectively 37319660Smckusickin the way discussed below. 37457011ScaelCommands may also be suffixed by 37557011Scael.Ql \&n , 37619660Smckusickmeaning the output of the command is to 37719660Smckusickbe line numbered. 37819660SmckusickThese suffixes may be combined in any order. 37957011Scael.Pp 38057011Scael.Bl -tag -width four -compact 38157011Scael.It Xo 38257011Scael.Po Ad \&. 38357011Scael.Pc Ns Cm \&a 38457011Scael.Xc 38557011Scael.It <text> 38657011Scael.It Cm \&. 38757011Scael.br 38819660SmckusickThe append command reads the given text 38919660Smckusickand appends it after the addressed line. 39057011Scael.Sq Ad \&. 39143083Scaelis left 39219660Smckusickon the last line input, if there 39319660Smckusickwere any, otherwise at the addressed line. 39419660SmckusickAddress `0' is legal for this command; text is placed 39519660Smckusickat the beginning of the buffer. 39657011Scael.Pp 39757011Scael.It Xo 39857011Scael.Po Ad \&. , Ns Ad \&. 39957011Scael.Pc Ns Cm \&c 40057011Scael.Xc 40157011Scael.It <text> 40257011Scael.It Cm \&. 40357011Scael.br 40419660SmckusickThe change 40519660Smckusickcommand deletes the addressed lines, then accepts input 40619660Smckusicktext which replaces these lines. 40757011Scael.Sq Ad \&. 40843083Scaelis left at the last line input; if there were none, 40919660Smckusickit is left at the line preceding the deleted lines. 41057011Scael.Pp 41157011Scael.It Xo 41257011Scael.Po Ad \&. , Ns Ad \&. 41357011Scael.Pc Ns Cm \&d 41457011Scael.Xc 41557011Scael.It <text> 41657011Scael.It Cm \&. 41757011Scael.br 41819660SmckusickThe delete command deletes the addressed lines from the buffer. 41919660SmckusickThe line originally after the last line deleted becomes the current line; 42019660Smckusickif the lines deleted were originally at the end, 42119660Smckusickthe new last line becomes the current line. 42257011Scael.Pp 42357011Scael.It Cm \&e Ar filename 42419660SmckusickThe edit 42519660Smckusickcommand causes the entire contents of the buffer to be deleted, 42619660Smckusickand then the named file to be read in. 42757011Scael.Sq Ad \&. 42843083Scaelis set to the last line of the buffer. 42919660SmckusickThe number of characters read is typed. 43043083Scael.Ar filename 43143083Scaelis remembered for possible use as a default file name 43219660Smckusickin a subsequent 43357011Scael.Cm \&r 43419660Smckusickor 43557011Scael.Cm \&w 43619660Smckusickcommand. 43743083ScaelIf 43843083Scael.Ar filename 43943083Scaelis missing, the remembered name is used. 44057011Scael.Pp 44157011Scael.It Cm \&E Ar filename 44219660SmckusickThis command is the same as 44357011Scael.Cm \&e , 44419660Smckusickexcept that no diagnostic results when no 44557011Scael.Cm \&w 44619660Smckusickhas been given since the last buffer alteration. 44757011Scael.Pp 44857011Scael.It Cm \&f Ar filename 44919660SmckusickThe filename command prints the currently remembered file name. 45043083ScaelIf 45143083Scael.Ar filename 45243083Scaelis given, 45343083Scaelthe currently remembered file name is changed to 45443083Scael.Ar filename . 45557011Scael.Sm off 45657011Scael.Pp 45757011Scael.It Xo 45857011Scael.Po Ad \&1 , Ns Ad \&$ 45957011Scael.Pc Cm \&g Ar "/regular\ expression/" Cm "command\ list" 46057011Scael.Xc 46157011Scael.Sm on 46219660SmckusickIn the global 46319660Smckusickcommand, the first step is to mark every line which matches 46419660Smckusickthe given regular expression. 46519660SmckusickThen for every such line, the 46643083Scaelgiven command list is executed with 46757011Scael.Sq Ad \&. 46843083Scaelinitially set to that line. 46919660SmckusickA single command or the first of multiple commands 47019660Smckusickappears on the same line with the global command. 47143083ScaelAll lines of a multi-line list except the last line must be ended with 47265227Smckusick.Sq Cm \&\e . 47357011Scael.Cm \&A , 47457011Scael.Cm \&i , 47519660Smckusickand 47657011Scael.Cm \&c 47719660Smckusickcommands and associated input are permitted; 47843083Scaelthe 47957011Scael.Sq Ad \&. 48043083Scaelterminating input mode may be omitted if it would be on the 48119660Smckusicklast line of the command list. 48219660SmckusickThe commands 48357011Scael.Cm \&g 48419660Smckusickand 48557011Scael.Cm \&v 48619660Smckusickare not permitted in the command list. 48757011Scael.Pp 48857011Scael.It Xo 48957011Scael.Po Ad \&. 49057011Scael.Pc Ns Cm \&i 49157011Scael.Xc 49257011Scael.It <text> 49357011Scael.It Cm \&. 49457011Scael.br 49519660SmckusickThis command inserts the given text before the addressed line. 49657011Scael.Sq Ad \&. 49743083Scaelis left at the last line input, or, if there were none, 49819660Smckusickat the line before the addressed line. 49919660SmckusickThis command differs from the 50057011Scael.Cm \&a 50119660Smckusickcommand only in the placement of the 50219660Smckusicktext. 50357011Scael.Pp 50457011Scael.It Xo 50557011Scael.Po Ad \&. , Ns Ad \&.+1 50657011Scael.Pc Ns Cm \&j 50757011Scael.Xc 50819660SmckusickThis command joins the addressed lines into a single line; 50919660Smckusickintermediate newlines simply disappear. 51057011Scael.Sq Ad \&. 51143083Scaelis left at the resulting line. 51257011Scael.Pp 51357011Scael.It Xo 51457011Scael.Po Ad \&. 51557011Scael.Pc Ns Cm k Ns Ar \&x 51657011Scael.Xc 51719660SmckusickThe mark command marks the addressed line with 51819660Smckusickname 51957011Scael.Ar \&x , 52019660Smckusickwhich must be a lower-case letter. 52143083ScaelThe address form 52257011Scael.Ar \(fmx 52343083Scaelthen addresses this line. 52457011Scael.Pp 52557011Scael.It Xo 52657011Scael.Po Ad \&. , Ns Ad \&. 52757011Scael.Pc Ns Cm \&l 52857011Scael.Xc 52919660SmckusickThe list command 53019660Smckusickprints the addressed lines in an unambiguous way: 53119660Smckusicknon-graphic characters are 53219660Smckusickprinted in two-digit octal, 53319660Smckusickand long lines are folded. 53419660SmckusickThe 53557011Scael.Ar \&l 53619660Smckusickcommand may be placed on the same line after any non-i/o 53719660Smckusickcommand. 53857011Scael.Pp 53957011Scael.It Xo 54057011Scael.Po Ad \&. , Ns Ad \&. 54157011Scael.Pc Ns Cm \&m Ns Ar \&a 54257011Scael.Xc 54319660SmckusickThe move command repositions the addressed lines after the line 54419660Smckusickaddressed by 54557011Scael.Ql Ad \&a . 54619660SmckusickThe last of the moved lines becomes the current line. 54757011Scael.Pp 54857011Scael.It Xo 54957011Scael.Po Ad \&. , Ns Ad \&. 55057011Scael.Pc Ns Cm \&p 55157011Scael.Xc 55219660SmckusickThe print command prints the addressed lines. 55357011Scael.Sq Ad \&. 55419660Smckusickis left at the last line printed. 55519660SmckusickThe 55657011Scael.Cm \&p 55719660Smckusickcommand 55819660Smckusickmay 55919660Smckusickbe placed on the same line after any non-i/o command. 56057011Scael.Pp 56157011Scael.It Xo 56257011Scael.Po Ad \&. , Ns Ad \&. 56357011Scael.Pc Ns Cm \&P 56457011Scael.Xc 56519660SmckusickThis command is a synonym for 56657011Scael.Cm \&p . 56757011Scael.Pp 56857011Scael.It Cm \&q 56919660SmckusickThe quit command causes 57057011Scael.Nm \&ed 57119660Smckusickto exit. 57219660SmckusickNo automatic write 57319660Smckusickof a file is done. 57457011Scael.Pp 57557011Scael.It Cm \&Q 57619660SmckusickThis command is the same as 57757011Scael.Cm \&q , 57819660Smckusickexcept that no diagnostic results when no 57957011Scael.Cm \&w 58019660Smckusickhas been given since the last buffer alteration. 58157011Scael.Pp 58257011Scael.It Xo 58357011Scael.Po Ad \&$ , Ns Ad \&. 58457011Scael.Pc Ns Cm \&r Ar filename 58557011Scael.Xc 58619660SmckusickThe read command 58719660Smckusickreads in the given file after the addressed line. 58819660SmckusickIf no file name is given, 58919660Smckusickthe remembered file name, if any, is used 59019660Smckusick(see 59157011Scael.Cm \&e 59219660Smckusickand 59357011Scael.Cm \&f 59443083Scaelcommands). 59519660SmckusickThe file name is remembered if there was no 59619660Smckusickremembered file name already. 59719660SmckusickAddress `0' is legal for 59857011Scael.Cm \&r 59919660Smckusickand causes the 60019660Smckusickfile to be read at the beginning of the buffer. 60119660SmckusickIf the read is successful, the number of characters 60219660Smckusickread is typed. 60357011Scael.Sq Ad \&. 60443083Scaelis left at the last line read in from the file. 60557011Scael.Sm off 60657011Scael.Pp 60757011Scael.It Xo 60857011Scael.Po Ad \&1 , Ns Ad \&$ 60957011Scael.Pc Cm \&g Ar "/regular\ expression/" Cm "replacement\ list" 61057011Scael.No " or," 61157011Scael.Xc 61257011Scael.Sm on 61357011Scael.Sm off 61457011Scael.It Xo 61557011Scael.Po Ad \&1 , Ns Ad \&$ 61657011Scael.Pc Cm \&g Ar "/regular\ expression/" Cm "replacement\ list/" 61757011Scael.Ns Cm \&g 61857011Scael.Xc 61957011Scael.Sm on 62019660SmckusickThe substitute command searches each addressed 62119660Smckusickline for an occurrence of the specified regular expression. 62219660SmckusickOn each line in which a match is found, 62319660Smckusickall matched strings are replaced by the replacement specified, 62443083Scaelif the global replacement indicator 62557011Scael.Cm \&g 62643083Scaelappears after the command. 62719660SmckusickIf the global indicator does not appear, only the first occurrence 62819660Smckusickof the matched string is replaced. 62919660SmckusickIt is an error for the substitution to fail on all addressed lines. 63019660SmckusickAny punctuation character 63143083Scaelmay be used instead of 63257011Scael.Sq Cm \&/ 63343083Scaelto delimit the regular expression 63419660Smckusickand the replacement. 63557011Scael.Sq Ad \&. 63643083Scaelis left at the last line substituted. 63743083ScaelAn ampersand 63857011Scael.Sq Cm \&& 63943083Scaelappearing in the replacement 64019660Smckusickis replaced by the string matching the regular expression. 64143083ScaelThe special meaning of 64257011Scael.Sq Cm \&& 64343083Scaelin this context may be 64443083Scaelsuppressed by preceding it by 64557011Scael.Sq Cm \&\e 64619660SmckusickThe characters 64757011Scael.Sq Cm \&\e Ns Ar \&n 64819660Smckusickwhere 64957011Scael.Ar \&n 65019660Smckusickis a digit, 65119660Smckusickare replaced by the text matched by the 65257011Scael.Ar \&n Ns 65319660Smckusickregular subexpression 65443083Scaelenclosed between 65557011Scael.Sq Cm \&\e\&( 65643083Scaeland 65757011Scael.Sq Cm \&\e\&) 65819660SmckusickWhen 65919660Smckusicknested, parenthesized subexpressions 66019660Smckusickare present, 66157011Scael.Ar \&n 66243083Scaelis determined by counting occurrences of 66357011Scael.Sq Cm \&\e\&( 66443083Scaelstarting from the left. 66519660SmckusickLines may be split by substituting new-line characters into them. 66619660SmckusickThe new-line in the 66719660Smckusickreplacement string 66843083Scaelmust be escaped by preceding it by 66957011Scael.Sq Cm \&\e 67019660SmckusickOne or two trailing delimiters may be omitted, 67143083Scaelimplying the 67257011Scael.Cm \&p 67343083Scaelsuffix. 67443083ScaelThe special form 67557011Scael.Cm \&s 67643083Scaelfollowed by 67757011Scael.Ar \&no 67819660Smckusickdelimiters 67919660Smckusickrepeats the most recent substitute command 68019660Smckusickon the addressed lines. 68143083ScaelThe 68257011Scael.Cm \&s 68343083Scaelmay be followed by the letters 68457011Scael.Cm \&r 68519660Smckusick(use the most recent regular expression for the 68619660Smckusickleft hand side, instead of the most recent 68719660Smckusickleft hand side of a substitute command), 68857011Scael.Cm \&p 68919660Smckusick(complement the setting of the 69057011Scael.Cm \&p 69119660Smckusicksuffix from the previous substitution), or 69257011Scael.Cm \&g 69319660Smckusick(complement the setting of the 69457011Scael.Cm \&g 69519660Smckusicksuffix). 69619660SmckusickThese letters may be combined in any order. 69757011Scael.Pp 69857011Scael.It Xo 69957011Scael.Po Ad \&. , Ns Ad \&. 70057011Scael.Pc Ns Cm \&t Ns Ar \&a 70157011Scael.Xc 70219660SmckusickThis command acts just like the 70357011Scael.Cm \&m 70419660Smckusickcommand, except that a copy of the addressed lines is placed 70519660Smckusickafter address 70657011Scael.Ad \&a 70719660Smckusick(which may be 0). 70857011Scael.Sq Ad \&. 70943083Scaelis left on the last line of the copy. 71057011Scael.Pp 71157011Scael.It Xo 71257011Scael.Po Ad \&. , Ns Ad \&. 71357011Scael.Pc Ns Cm \&u 71457011Scael.Xc 71519660SmckusickThe undo command restores the buffer to it's state 71619660Smckusickbefore the most recent buffer modifying command. 71719660SmckusickThe current line is also restored. 71819660SmckusickBuffer modifying commands are 71957011Scael.Cm \&a , \&c , \&d , \&g , 72057011Scael.Cm \&i , \&k , \&m , \&r , 72157011Scael.Cm \&s , \&t , 72219660Smckusickand 72357011Scael.Cm \&v . 72419660SmckusickFor purposes of undo, 72557011Scael.Cm \&g 72619660Smckusickand 72757011Scael.Cm \&v 72819660Smckusickare considered to be a single buffer modifying command. 72919660SmckusickUndo is its own inverse. 73019660SmckusickWhen 73157011Scael.Nm \&ed 73219660Smckusickruns out of memory 73319660Smckusick(at about 8000 lines on any 16 bit mini-computer 73419660Smckusicksuch as the PDP-11) 73565227Smckusickthis full undo is not possible, and 73657011Scael.Cm \&u 73719660Smckusickcan only undo the effect of the most recent 73819660Smckusicksubstitute on the current line. 73919660SmckusickThis restricted undo also applies to editor scripts 74019660Smckusickwhen 74157011Scael.Nm \&ed 74219660Smckusickis invoked with the 74343083Scael.Fl 74419660Smckusickoption. 74557011Scael.Sm off 74657011Scael.Pp 74757011Scael.It Xo 74857011Scael.Po Ad \&1 , Ns Ad \&$ 74957011Scael.Pc Cm \&v Ar "/regular\ expression/" Cm "command\ list" 75057011Scael.Xc 75157011Scael.Sm on 75219660SmckusickThis command is the same as the global command 75357011Scael.Cm \&g 75419660Smckusickexcept that the command list is executed 75557011Scael.Cm \&g 75643083Scaelwith 75757011Scael.Sq Ad \&. 75843083Scaelinitially set to every line 75943083Scael.Em except 76019660Smckusickthose 76119660Smckusickmatching the regular expression. 76257011Scael.Pp 76357011Scael.It Xo 76457011Scael.Po Ad \&1 , Ns Ad \&$ 76557011Scael.Pc Ns Cm \&w Ar filename 76657011Scael.Xc 76719660SmckusickThe write command writes the addressed lines onto 76819660Smckusickthe given file. 76919660SmckusickIf the file does not exist, 77019660Smckusickit is created. 77143083ScaelThe file name is remembered if there was no 77219660Smckusickremembered file name already. 77319660SmckusickIf no file name is given, 77419660Smckusickthe remembered file name, if any, is used 77519660Smckusick(see 77657011Scael.Cm \&e 77719660Smckusickand 77857011Scael.Cm \&f 77943083Scaelcommands). 78057011Scael.Sq Ad \&. 78143083Scaelis unchanged. 78219660SmckusickIf the command is successful, the number of characters written is 78319660Smckusickprinted. 78457011Scael.Pp 78557011Scael.It Xo 78657011Scael.Po Ad \&1 , Ns Ad \&$ 78757011Scael.Pc Ns Cm \&W Ar filename 78857011Scael.Xc 78919660SmckusickThis command is the same as 79057011Scael.Cm \&w , 79119660Smckusickexcept that the addressed lines are appended to the file. 79257011Scael.Pp 79357011Scael.It Xo 79457011Scael.Po Ad \&1 , Ns Ad \&$ 79557011Scael.Pc Ns Cm \&wq Ar filename 79657011Scael.Xc 79719660SmckusickThis command is the same as 79857011Scael.Cm \&w 79919660Smckusickexcept that afterwards a 80057011Scael.Cm \&q 80119660Smckusickcommand is done, 80219660Smckusickexiting the editor 80319660Smckusickafter the file is written. 80457011Scael.Pp 80557011Scael.It Xo 80657011Scael.Po Ad \&.+1 80757011Scael.Pc Ns Cm \&z 80857011Scael.No " or," 80957011Scael.Xc 81057011Scael.It Xo 81157011Scael.Po Ad \&.+1 81257011Scael.Pc Ns Cm \&z Ns Ar \&n 81357011Scael.Xc 81419660SmckusickThis command scrolls through the buffer starting at the addressed line. 81519660Smckusick22 (or 81657011Scael.Ar \&n , 81719660Smckusickif given) 81819660Smckusicklines are printed. 81919660SmckusickThe last line printed becomes the current line. 82019660SmckusickThe value 82157011Scael.Ar \&n 82219660Smckusickis sticky, in that it becomes the default for 82319660Smckusickfuture 82457011Scael.Cm \&z 82519660Smckusickcommands. 82657011Scael.Pp 82757011Scael.It Xo 82857011Scael.Po Ad \&$ 82957011Scael.Pc Ns Cm \&= 83057011Scael.Xc 83119660SmckusickThe line number of the addressed line is typed. 83257011Scael.Sq Ad \&. 83343083Scaelis unchanged by this command. 83457011Scael.Pp 83557011Scael.It Xo 83657011Scael.Ad \&! Ns Aq shell\ command 83757011Scael.Xc 83857011ScaelThe remainder of the line after the 83957011Scael.Ql Cm \&! 84057011Scaelis sent 84119660Smckusickto 84257011Scael.Xr sh 1 84319660Smckusickto be interpreted as a command. 84457011Scael.Sq Ad \&. 84519660Smckusickis unchanged. 84657011Scael.Pp 84757011Scael.It Xo 84857011Scael.Po Ad \&.+1 , Ns Ad \&.+1 84957011Scael.Pc Ns Aq newline 85057011Scael.Xc 85119660SmckusickAn address alone on a line causes the addressed line to be printed. 85243083ScaelA blank line alone is equivalent to 85357011Scael.Ad .+1 85443083Scaelit is useful 85519660Smckusickfor stepping through text. 85619660SmckusickIf two addresses are present with no 85719660Smckusickintervening semicolon, 85857011Scael.Nm \&ed 85919660Smckusickprints the range of lines. 86019660SmckusickIf they are separated by a semicolon, 86119660Smckusickthe second line is printed. 86257011Scael.El 86343083Scael.Pp 86457011ScaelIf an interrupt signal 86557011Scael.Pq Tn ASCII DEL 86657011Scaelis sent, 86757011Scael.Nm \&ed 86843083Scaelprints 86943083Scael.Sq Li ?interrupted 87019660Smckusickand returns to its command level. 87143083Scael.Pp 87219660SmckusickSome size limitations: 87319660Smckusick512 characters per line, 87419660Smckusick256 characters per global command list, 87519660Smckusick64 characters per file name, 87619660Smckusickand, on mini computers, 87719660Smckusick128K characters in the temporary file. 87819660SmckusickThe limit on the number of lines depends on the amount of core: 87919660Smckusickeach line takes 2 words. 88043083Scael.Pp 88119660SmckusickWhen reading a file, 88257011Scael.Nm \&ed 88357011Scaeldiscards 88457011Scael.Tn ASCII NUL 88557011Scaelcharacters 88619660Smckusickand all characters after the last newline. 88757011ScaelIt refuses to read files containing 88857011Scael.Ns non- Tn ASCII 88957011Scaelcharacters. 89043083Scael.Sh FILES 89157011Scael.Bl -tag -compact -width "/tmp/ed*" 89257011Scael.It Pa /tmp/e* 89357011Scael.It Pa edhup 89443083Scaelwork is saved here if terminal hangs up 89557011Scael.El 89643083Scael.Sh SEE ALSO 89757011Scael.Xr \&ex 1 , 89843083Scael.Xr sed 1 , 89943083Scael.Xr crypt 1 90019660Smckusick.br 90119660SmckusickB. W. Kernighan, 90243083Scael.Em A Tutorial Introduction to the ED Text Editor 90319660Smckusick.br 90419660SmckusickB. W. Kernighan, 90543083Scael.Em Ar Advanced editing on UNIX 90643083Scael.Sh HISTORY 90743083ScaelThe 90857011Scael.Nm \&ed 90957011Scaelcommand appeared in 91065227Smckusick.At v6 . 91143083Scael.Sh DIAGNOSTICS 91243083Scael.Sq Li name 91343083Scaelfor inaccessible file; 91443083Scael.Sq Li ?self-explanatory message 91519660Smckusickfor other errors. 91643083Scael.Pp 91719660SmckusickTo protect against throwing away valuable work, 91819660Smckusicka 91957011Scael.Cm \&q 92019660Smckusickor 92157011Scael.Cm \&e 92219660Smckusickcommand is considered to be in error, unless a 92357011Scael.Cm \&w 92419660Smckusickhas occurred since the last buffer change. 92519660SmckusickA second 92657011Scael.Cm \&q 92719660Smckusickor 92857011Scael.Cm \&e 92919660Smckusickwill be obeyed regardless. 93043083Scael.Sh BUGS 93143083ScaelThe 93257011Scael.Cm \&l 93343083Scaelcommand mishandles 93443083Scael.Li DEL . 93519660Smckusick.br 93619660SmckusickThe 93757011Scael.Cm \&undo 93819660Smckusickcommand causes marks to be lost on affected lines. 93947305Scael.br 940*67457SmckusickThe special treatment of hangups only works on 94157011Scael.Ux . 942