13ce57932SGordon Bergling.Dd April 9, 2021 200c2adfeSPhilippe Charnier.Dt ED 1 300c2adfeSPhilippe Charnier.Os 400c2adfeSPhilippe Charnier.Sh NAME 5daa40efdSAlexey Zelkin.Nm ed , 6daa40efdSAlexey Zelkin.Nm red 700c2adfeSPhilippe Charnier.Nd text editor 800c2adfeSPhilippe Charnier.Sh SYNOPSIS 9be8b1497SRuslan Ermilov.Nm 1000c2adfeSPhilippe Charnier.Op Fl 11d83db3fbSConrad Meyer.Op Fl s 1200c2adfeSPhilippe Charnier.Op Fl p Ar string 1300c2adfeSPhilippe Charnier.Op Ar file 1409152a86SGiorgos Keramidas.Nm red 1509152a86SGiorgos Keramidas.Op Fl 16d83db3fbSConrad Meyer.Op Fl s 1709152a86SGiorgos Keramidas.Op Fl p Ar string 1809152a86SGiorgos Keramidas.Op Ar file 1900c2adfeSPhilippe Charnier.Sh DESCRIPTION 20e004acc8SPhilippe CharnierThe 21e004acc8SPhilippe Charnier.Nm 22e004acc8SPhilippe Charnierutility is a line-oriented text editor. 2330154ac8SAndrew MooreIt is used to create, display, modify and otherwise manipulate text 2430154ac8SAndrew Moorefiles. 2509152a86SGiorgos KeramidasWhen invoked as 2609152a86SGiorgos Keramidas.Nm red , 2709152a86SGiorgos Keramidasthe editor runs in 2809152a86SGiorgos Keramidas.Qq restricted 2909152a86SGiorgos Keramidasmode, in which the only difference is that the editor restricts the 3009152a86SGiorgos Keramidasuse of filenames which start with 3109152a86SGiorgos Keramidas.Ql \&! 3209152a86SGiorgos Keramidas(interpreted as shell commands by 3373ca71feSRuslan Ermilov.Nm ) 3409152a86SGiorgos Keramidasor contain a 3509152a86SGiorgos Keramidas.Ql \&/ . 3609152a86SGiorgos KeramidasNote that editing outside of the current directory is only prohibited 3709152a86SGiorgos Keramidasif the user does not have write access to the current directory. 3809152a86SGiorgos KeramidasIf a user has write access to the current directory, then symbolic 3909152a86SGiorgos Keramidaslinks can be created in the current directory, in which case 4009152a86SGiorgos Keramidas.Nm red 4109152a86SGiorgos Keramidaswill not stop the user from editing the file that the symbolic link 4209152a86SGiorgos Keramidaspoints to. 4312e720d7SRuslan Ermilov.Pp 4430154ac8SAndrew MooreIf invoked with a 4500c2adfeSPhilippe Charnier.Ar file 4630154ac8SAndrew Mooreargument, then a copy of 4700c2adfeSPhilippe Charnier.Ar file 4830154ac8SAndrew Mooreis read into the editor's buffer. 4930154ac8SAndrew MooreChanges are made to this copy and not directly to 5000c2adfeSPhilippe Charnier.Ar file 5130154ac8SAndrew Mooreitself. 5230154ac8SAndrew MooreUpon quitting 53be8b1497SRuslan Ermilov.Nm , 5430154ac8SAndrew Mooreany changes not explicitly saved with a 5500c2adfeSPhilippe Charnier.Em w 5630154ac8SAndrew Moorecommand are lost. 5712e720d7SRuslan Ermilov.Pp 5830154ac8SAndrew MooreEditing is done in two distinct modes: 5900c2adfeSPhilippe Charnier.Em command 6030154ac8SAndrew Mooreand 6100c2adfeSPhilippe Charnier.Em input . 6230154ac8SAndrew MooreWhen first invoked, 6300c2adfeSPhilippe Charnier.Nm 6430154ac8SAndrew Mooreis in command mode. 6530154ac8SAndrew MooreIn this mode commands are read from the standard input and 6630154ac8SAndrew Mooreexecuted to manipulate the contents of the editor buffer. 6730154ac8SAndrew MooreA typical command might look like: 6800c2adfeSPhilippe Charnier.Pp 6900c2adfeSPhilippe Charnier.Sm off 7000c2adfeSPhilippe Charnier.Cm ,s No / Em old Xo 7100c2adfeSPhilippe Charnier.No / Em new 7200c2adfeSPhilippe Charnier.No / Cm g 7300c2adfeSPhilippe Charnier.Xc 7400c2adfeSPhilippe Charnier.Sm on 7500c2adfeSPhilippe Charnier.Pp 7660fd953fSJordan K. Hubbardwhich replaces all occurrences of the string 7700c2adfeSPhilippe Charnier.Em old 7830154ac8SAndrew Moorewith 7900c2adfeSPhilippe Charnier.Em new . 8000c2adfeSPhilippe Charnier.Pp 8130154ac8SAndrew MooreWhen an input command, such as 8200c2adfeSPhilippe Charnier.Em a 8330154ac8SAndrew Moore(append), 8400c2adfeSPhilippe Charnier.Em i 8530154ac8SAndrew Moore(insert) or 8600c2adfeSPhilippe Charnier.Em c 8730154ac8SAndrew Moore(change), is given, 8800c2adfeSPhilippe Charnier.Nm 8973ca71feSRuslan Ermiloventers input mode. 9073ca71feSRuslan ErmilovThis is the primary means 9130154ac8SAndrew Mooreof adding text to a file. 9230154ac8SAndrew MooreIn this mode, no commands are available; 9330154ac8SAndrew Mooreinstead, the standard input is written 9473ca71feSRuslan Ermilovdirectly to the editor buffer. 9573ca71feSRuslan ErmilovLines consist of text up to and 9630154ac8SAndrew Mooreincluding a 9700c2adfeSPhilippe Charnier.Em newline 9830154ac8SAndrew Moorecharacter. 9930154ac8SAndrew MooreInput mode is terminated by 10000c2adfeSPhilippe Charnierentering a single period 10112e720d7SRuslan Ermilov.Pq Em .\& 10200c2adfeSPhilippe Charnieron a line. 10300c2adfeSPhilippe Charnier.Pp 10430154ac8SAndrew MooreAll 10500c2adfeSPhilippe Charnier.Nm 10630154ac8SAndrew Moorecommands operate on whole lines or ranges of lines; e.g., 10730154ac8SAndrew Moorethe 10800c2adfeSPhilippe Charnier.Em d 10930154ac8SAndrew Moorecommand deletes lines; the 11000c2adfeSPhilippe Charnier.Em m 11130154ac8SAndrew Moorecommand moves lines, and so on. 11230154ac8SAndrew MooreIt is possible to modify only a portion of a line by means of replacement, 11373ca71feSRuslan Ermilovas in the example above. 11473ca71feSRuslan ErmilovHowever even here, the 11500c2adfeSPhilippe Charnier.Em s 11630154ac8SAndrew Moorecommand is applied to whole lines at a time. 11700c2adfeSPhilippe Charnier.Pp 11830154ac8SAndrew MooreIn general, 11900c2adfeSPhilippe Charnier.Nm 12030154ac8SAndrew Moorecommands consist of zero or more line addresses, followed by a single 12130154ac8SAndrew Moorecharacter command and possibly additional parameters; i.e., 12230154ac8SAndrew Moorecommands have the structure: 12300c2adfeSPhilippe Charnier.Pp 12400c2adfeSPhilippe Charnier.Sm off 125d0353b83SRuslan Ermilov.Xo 126d0353b83SRuslan Ermilov.Op Ar address Op , Ar address 127d0353b83SRuslan Ermilov.Ar command Op Ar parameters 12800c2adfeSPhilippe Charnier.Xc 12900c2adfeSPhilippe Charnier.Sm on 13000c2adfeSPhilippe Charnier.Pp 13110ca1c6cSAndrew MooreThe address(es) indicate the line or range of lines to be affected by the 13273ca71feSRuslan Ermilovcommand. 13373ca71feSRuslan ErmilovIf fewer addresses are given than the command accepts, then 13410ca1c6cSAndrew Mooredefault addresses are supplied. 13500c2adfeSPhilippe Charnier.Sh OPTIONS 13600c2adfeSPhilippe CharnierThe following options are available: 13700c2adfeSPhilippe Charnier.Bl -tag -width indent 13800c2adfeSPhilippe Charnier.It Fl s 139bef84d6bSSheldon HearnSuppress diagnostics. 140bef84d6bSSheldon HearnThis should be used if 14100c2adfeSPhilippe Charnier.Nm Ns 's 14230154ac8SAndrew Moorestandard input is from a script. 14300c2adfeSPhilippe Charnier.It Fl p Ar string 14473ca71feSRuslan ErmilovSpecify a command prompt. 14573ca71feSRuslan ErmilovThis may be toggled on and off with the 14600c2adfeSPhilippe Charnier.Em P 14730154ac8SAndrew Moorecommand. 14800c2adfeSPhilippe Charnier.It Ar file 14973ca71feSRuslan ErmilovSpecify the name of a file to read. 15073ca71feSRuslan ErmilovIf 15100c2adfeSPhilippe Charnier.Ar file 15230154ac8SAndrew Mooreis prefixed with a 15373ca71feSRuslan Ermilovbang (!), then it is interpreted as a shell command. 15473ca71feSRuslan ErmilovIn this case, 15530154ac8SAndrew Moorewhat is read is 15630154ac8SAndrew Moorethe standard output of 15700c2adfeSPhilippe Charnier.Ar file 15830154ac8SAndrew Mooreexecuted via 15900c2adfeSPhilippe Charnier.Xr sh 1 . 16030154ac8SAndrew MooreTo read a file whose name begins with a bang, prefix the 16130154ac8SAndrew Moorename with a backslash (\\). 16230154ac8SAndrew MooreThe default filename is set to 16300c2adfeSPhilippe Charnier.Ar file 16430154ac8SAndrew Mooreonly if it is not prefixed with a bang. 16500c2adfeSPhilippe Charnier.El 16600c2adfeSPhilippe Charnier.Sh LINE ADDRESSING 16795e6217eSAndrew MooreAn address represents the number of a line in the buffer. 168e004acc8SPhilippe CharnierThe 169e004acc8SPhilippe Charnier.Nm 170e004acc8SPhilippe Charnierutility maintains a 17100c2adfeSPhilippe Charnier.Em current address 17230154ac8SAndrew Moorewhich is 17330154ac8SAndrew Mooretypically supplied to commands as the default address when none is specified. 17430154ac8SAndrew MooreWhen a file is first read, the current address is set to the last line 17573ca71feSRuslan Ermilovof the file. 17673ca71feSRuslan ErmilovIn general, the current address is set to the last line 17730154ac8SAndrew Mooreaffected by a command. 17800c2adfeSPhilippe Charnier.Pp 17930154ac8SAndrew MooreA line address is 18030154ac8SAndrew Mooreconstructed from one of the bases in the list below, optionally followed 18173ca71feSRuslan Ermilovby a numeric offset. 18273ca71feSRuslan ErmilovThe offset may include any combination 18330154ac8SAndrew Mooreof digits, operators (i.e., 18400c2adfeSPhilippe Charnier.Em + , 18500c2adfeSPhilippe Charnier.Em - 18630154ac8SAndrew Mooreand 18700c2adfeSPhilippe Charnier.Em ^ ) 18830154ac8SAndrew Mooreand whitespace. 18930154ac8SAndrew MooreAddresses are read from left to right, and their values are computed 19030154ac8SAndrew Moorerelative to the current address. 19100c2adfeSPhilippe Charnier.Pp 19230154ac8SAndrew MooreOne exception to the rule that addresses represent line numbers is the 19330154ac8SAndrew Mooreaddress 19400c2adfeSPhilippe Charnier.Em 0 19530154ac8SAndrew Moore(zero). 19630154ac8SAndrew MooreThis means "before the first line," 19730154ac8SAndrew Mooreand is legal wherever it makes sense. 19800c2adfeSPhilippe Charnier.Pp 19930154ac8SAndrew MooreAn address range is two addresses separated either by a comma or 200bef84d6bSSheldon Hearnsemi-colon. 201bef84d6bSSheldon HearnThe value of the first address in a range cannot exceed the 20273ca71feSRuslan Ermilovvalue of the second. 20373ca71feSRuslan ErmilovIf only one address is given in a range, then 20473ca71feSRuslan Ermilovthe second address is set to the given address. 20573ca71feSRuslan ErmilovIf an 20600c2adfeSPhilippe Charnier.Em n Ns -tuple 20730154ac8SAndrew Mooreof addresses is given where 20800c2adfeSPhilippe Charnier.Em "n\ >\ 2" , 20995e6217eSAndrew Moorethen the corresponding range is determined by the last two addresses in 21095e6217eSAndrew Moorethe 21100c2adfeSPhilippe Charnier.Em n Ns -tuple . 21295e6217eSAndrew MooreIf only one address is expected, then the last address is used. 21300c2adfeSPhilippe Charnier.Pp 21430154ac8SAndrew MooreEach address in a comma-delimited range is interpreted relative to the 21573ca71feSRuslan Ermilovcurrent address. 21673ca71feSRuslan ErmilovIn a semi-colon-delimited range, the first address is 21730154ac8SAndrew Mooreused to set the current address, and the second address is interpreted 21830154ac8SAndrew Moorerelative to the first. 21900c2adfeSPhilippe Charnier.Pp 22000c2adfeSPhilippe CharnierThe following address symbols are recognized: 22100c2adfeSPhilippe Charnier.Bl -tag -width indent 22200c2adfeSPhilippe Charnier.It . 22330154ac8SAndrew MooreThe current line (address) in the buffer. 22400c2adfeSPhilippe Charnier.It $ 22530154ac8SAndrew MooreThe last line in the buffer. 22600c2adfeSPhilippe Charnier.It n 22730154ac8SAndrew MooreThe 228f68fbfedSRebecca Cran.Em n Ns th 22930154ac8SAndrew Mooreline in the buffer 23030154ac8SAndrew Moorewhere 23100c2adfeSPhilippe Charnier.Em n 23230154ac8SAndrew Mooreis a number in the range 23300c2adfeSPhilippe Charnier.Em [0,$] . 23400c2adfeSPhilippe Charnier.It - or ^ 23530154ac8SAndrew MooreThe previous line. 23630154ac8SAndrew MooreThis is equivalent to 23700c2adfeSPhilippe Charnier.Em -1 23830154ac8SAndrew Mooreand may be repeated with cumulative effect. 23900c2adfeSPhilippe Charnier.It -n or ^n 24030154ac8SAndrew MooreThe 24100c2adfeSPhilippe Charnier.Em n Ns th 24230154ac8SAndrew Mooreprevious line, where 24300c2adfeSPhilippe Charnier.Em n 24430154ac8SAndrew Mooreis a non-negative number. 24500c2adfeSPhilippe Charnier.It + 24600c2adfeSPhilippe CharnierThe next line. 24730154ac8SAndrew MooreThis is equivalent to 24800c2adfeSPhilippe Charnier.Em +1 24930154ac8SAndrew Mooreand may be repeated with cumulative effect. 250056103b6SJoseph Koshy.It +n 25130154ac8SAndrew MooreThe 25200c2adfeSPhilippe Charnier.Em n Ns th 25330154ac8SAndrew Moorenext line, where 25400c2adfeSPhilippe Charnier.Em n 25530154ac8SAndrew Mooreis a non-negative number. 25600c2adfeSPhilippe Charnier.It , or % 25773ca71feSRuslan ErmilovThe first through last lines in the buffer. 25873ca71feSRuslan ErmilovThis is equivalent to 25930154ac8SAndrew Moorethe address range 26000c2adfeSPhilippe Charnier.Em 1,$ . 26100c2adfeSPhilippe Charnier.It ; 26273ca71feSRuslan ErmilovThe current through last lines in the buffer. 26373ca71feSRuslan ErmilovThis is equivalent to 26430154ac8SAndrew Moorethe address range 26500c2adfeSPhilippe Charnier.Em .,$ . 26600c2adfeSPhilippe Charnier.It /re/ 26700c2adfeSPhilippe CharnierThe next line containing the regular expression 26800c2adfeSPhilippe Charnier.Em re . 26930154ac8SAndrew MooreThe search wraps to the beginning of the buffer and continues down to the 27030154ac8SAndrew Moorecurrent line, if necessary. 27130154ac8SAndrew Moore// repeats the last search. 27200c2adfeSPhilippe Charnier.It ?re? 27330154ac8SAndrew MooreThe 27430154ac8SAndrew Mooreprevious line containing the regular expression 27500c2adfeSPhilippe Charnier.Em re . 27630154ac8SAndrew MooreThe search wraps to the end of the buffer and continues up to the 27730154ac8SAndrew Moorecurrent line, if necessary. 27830154ac8SAndrew Moore?? repeats the last search. 27900c2adfeSPhilippe Charnier.It 'lc 28030154ac8SAndrew MooreThe 28130154ac8SAndrew Mooreline previously marked by a 28200c2adfeSPhilippe Charnier.Em k 28330154ac8SAndrew Moore(mark) command, where 28400c2adfeSPhilippe Charnier.Em lc 28530154ac8SAndrew Mooreis a lower case letter. 28600c2adfeSPhilippe Charnier.El 28700c2adfeSPhilippe Charnier.Sh REGULAR EXPRESSIONS 28830154ac8SAndrew MooreRegular expressions are patterns used in selecting text. 28900c2adfeSPhilippe CharnierFor example, the command: 29000c2adfeSPhilippe Charnier.Pp 29100c2adfeSPhilippe Charnier.Sm off 29200c2adfeSPhilippe Charnier.Cm g No / Em string Xo 29300c2adfeSPhilippe Charnier.No / 29400c2adfeSPhilippe Charnier.Xc 29500c2adfeSPhilippe Charnier.Sm on 29600c2adfeSPhilippe Charnier.Pp 29730154ac8SAndrew Mooreprints all lines containing 29800c2adfeSPhilippe Charnier.Em string . 29930154ac8SAndrew MooreRegular expressions are also 30030154ac8SAndrew Mooreused by the 30100c2adfeSPhilippe Charnier.Em s 30230154ac8SAndrew Moorecommand for selecting old text to be replaced with new. 30300c2adfeSPhilippe Charnier.Pp 30430154ac8SAndrew MooreIn addition to a specifying string literals, regular expressions can 30530154ac8SAndrew Moorerepresent 30673ca71feSRuslan Ermilovclasses of strings. 30773ca71feSRuslan ErmilovStrings thus represented are said to be matched 30830154ac8SAndrew Mooreby the corresponding regular expression. 30930154ac8SAndrew MooreIf it is possible for a regular expression 31030154ac8SAndrew Mooreto match several strings in a line, then the left-most longest match is 31130154ac8SAndrew Moorethe one selected. 31200c2adfeSPhilippe Charnier.Pp 31330154ac8SAndrew MooreThe following symbols are used in constructing regular expressions: 31400c2adfeSPhilippe Charnier.Bl -tag -width indent 31500c2adfeSPhilippe Charnier.It c 31630154ac8SAndrew MooreAny character 31700c2adfeSPhilippe Charnier.Em c 31873ca71feSRuslan Ermilovnot listed below, including 31973ca71feSRuslan Ermilov.Ql \&{ , 32073ca71feSRuslan Ermilov.Ql \&} , 32173ca71feSRuslan Ermilov.Ql \&( , 32273ca71feSRuslan Ermilov.Ql \&) , 32373ca71feSRuslan Ermilov.Ql < 32473ca71feSRuslan Ermilovand 32573ca71feSRuslan Ermilov.Ql > , 32630154ac8SAndrew Moorematches itself. 32700c2adfeSPhilippe Charnier.It Pf \e c 32830154ac8SAndrew MooreAny backslash-escaped character 32900c2adfeSPhilippe Charnier.Em c , 33073ca71feSRuslan Ermilovexcept for 33173ca71feSRuslan Ermilov.Ql \&{ , 33273ca71feSRuslan Ermilov.Ql \&} , 33373ca71feSRuslan Ermilov.Ql \&( , 33473ca71feSRuslan Ermilov.Ql \&) , 33573ca71feSRuslan Ermilov.Ql < 33673ca71feSRuslan Ermilovand 33773ca71feSRuslan Ermilov.Ql > , 33830154ac8SAndrew Moorematches itself. 33900c2adfeSPhilippe Charnier.It . 34000c2adfeSPhilippe CharnierMatch any single character. 34100c2adfeSPhilippe Charnier.It Op char-class 34200c2adfeSPhilippe CharnierMatch any single character in 34300c2adfeSPhilippe Charnier.Em char-class . 34473ca71feSRuslan ErmilovTo include a 34573ca71feSRuslan Ermilov.Ql \&] 34630154ac8SAndrew Moorein 34700c2adfeSPhilippe Charnier.Em char-class , 34830154ac8SAndrew Mooreit must be the first character. 34930154ac8SAndrew MooreA range of characters may be specified by separating the end characters 35073ca71feSRuslan Ermilovof the range with a 35173ca71feSRuslan Ermilov.Ql - , 35273ca71feSRuslan Ermilove.g., 35373ca71feSRuslan Ermilov.Ql a-z 35473ca71feSRuslan Ermilovspecifies the lower case characters. 35530154ac8SAndrew MooreThe following literal expressions can also be used in 35600c2adfeSPhilippe Charnier.Em char-class 35730154ac8SAndrew Mooreto specify sets of characters: 35800c2adfeSPhilippe Charnier.Pp 3591bdbdb45SRuslan Ermilov.Bl -column "[:alnum:]" "[:cntrl:]" "[:lower:]" "[:xdigit:]" -compact 3602b0a73baSRuslan Ermilov.It [:alnum:] Ta [:cntrl:] Ta [:lower:] Ta [:space:] 3612b0a73baSRuslan Ermilov.It [:alpha:] Ta [:digit:] Ta [:print:] Ta [:upper:] 3622b0a73baSRuslan Ermilov.It [:blank:] Ta [:graph:] Ta [:punct:] Ta [:xdigit:] 3632b0a73baSRuslan Ermilov.El 36400c2adfeSPhilippe Charnier.Pp 36573ca71feSRuslan ErmilovIf 36673ca71feSRuslan Ermilov.Ql - 36773ca71feSRuslan Ermilovappears as the first or last 36830154ac8SAndrew Moorecharacter of 36900c2adfeSPhilippe Charnier.Em char-class , 37030154ac8SAndrew Moorethen it matches itself. 37130154ac8SAndrew MooreAll other characters in 37200c2adfeSPhilippe Charnier.Em char-class 37330154ac8SAndrew Moorematch themselves. 37400c2adfeSPhilippe Charnier.Pp 37530154ac8SAndrew MoorePatterns in 376056103b6SJoseph Koshy.Em char-class 37730154ac8SAndrew Mooreof the form: 37800c2adfeSPhilippe Charnier.Pp 3792b0a73baSRuslan Ermilov.Bl -item -compact -offset 2n 3802b0a73baSRuslan Ermilov.It 3811586940eSRuslan Ermilov.Op \&. Ns Ar col-elm Ns .\& 3822b0a73baSRuslan Ermilovor, 3832b0a73baSRuslan Ermilov.It 3842b0a73baSRuslan Ermilov.Op = Ns Ar col-elm Ns = 3852b0a73baSRuslan Ermilov.El 38600c2adfeSPhilippe Charnier.Pp 38730154ac8SAndrew Moorewhere 3882b0a73baSRuslan Ermilov.Ar col-elm 38930154ac8SAndrew Mooreis a 39000c2adfeSPhilippe Charnier.Em collating element 391b093b412SGiorgos Keramidasare interpreted according to the current locale settings 39230154ac8SAndrew Moore(not currently supported). 39330154ac8SAndrew MooreSee 39400c2adfeSPhilippe Charnier.Xr regex 3 395b093b412SGiorgos Keramidasand 396b093b412SGiorgos Keramidas.Xr re_format 7 39730154ac8SAndrew Moorefor an explanation of these constructs. 39800c2adfeSPhilippe Charnier.It Op ^char-class 39900c2adfeSPhilippe CharnierMatch any single character, other than newline, not in 40000c2adfeSPhilippe Charnier.Em char-class . 40100c2adfeSPhilippe Charnier.Em Char-class 40230154ac8SAndrew Mooreis defined 40330154ac8SAndrew Mooreas above. 40400c2adfeSPhilippe Charnier.It ^ 40500c2adfeSPhilippe CharnierIf 40600c2adfeSPhilippe Charnier.Em ^ 40700c2adfeSPhilippe Charnieris the first character of a regular expression, then it 40830154ac8SAndrew Mooreanchors the regular expression to the beginning of a line. 40930154ac8SAndrew MooreOtherwise, it matches itself. 41000c2adfeSPhilippe Charnier.It $ 41100c2adfeSPhilippe CharnierIf 41200c2adfeSPhilippe Charnier.Em $ 41300c2adfeSPhilippe Charnieris the last character of a regular expression, it 41430154ac8SAndrew Mooreanchors the regular expression to the end of a line. 41530154ac8SAndrew MooreOtherwise, it matches itself. 41600c2adfeSPhilippe Charnier.It Pf \e < 41700c2adfeSPhilippe CharnierAnchor the single character regular expression or subexpression 41830154ac8SAndrew Mooreimmediately following it to the beginning of a word. 41930154ac8SAndrew Moore(This may not be available) 42000c2adfeSPhilippe Charnier.It Pf \e > 42100c2adfeSPhilippe CharnierAnchor the single character regular expression or subexpression 42230154ac8SAndrew Mooreimmediately following it to the end of a word. 42330154ac8SAndrew Moore(This may not be available) 42400c2adfeSPhilippe Charnier.It Pf \e (re\e) 42500c2adfeSPhilippe CharnierDefine a subexpression 42600c2adfeSPhilippe Charnier.Em re . 42730154ac8SAndrew MooreSubexpressions may be nested. 42800c2adfeSPhilippe CharnierA subsequent backreference of the form 429c2d03ea8SRuslan Ermilov.Pf \e Em n , 43000c2adfeSPhilippe Charnierwhere 43100c2adfeSPhilippe Charnier.Em n 43230154ac8SAndrew Mooreis a number in the range [1,9], expands to the text matched by the 43300c2adfeSPhilippe Charnier.Em n Ns th 43430154ac8SAndrew Mooresubexpression. 43573ca71feSRuslan ErmilovFor example, the regular expression 43673ca71feSRuslan Ermilov.Ql \e(.*\e)\e1 43773ca71feSRuslan Ermilovmatches any string 43830154ac8SAndrew Mooreconsisting of identical adjacent substrings. 43930154ac8SAndrew MooreSubexpressions are ordered relative to 44030154ac8SAndrew Mooretheir left delimiter. 44100c2adfeSPhilippe Charnier.It * 44200c2adfeSPhilippe CharnierMatch the single character regular expression or subexpression 44373ca71feSRuslan Ermilovimmediately preceding it zero or more times. 44473ca71feSRuslan ErmilovIf 44500c2adfeSPhilippe Charnier.Em * 44600c2adfeSPhilippe Charnieris the first 44730154ac8SAndrew Moorecharacter of a regular expression or subexpression, then it matches 44873ca71feSRuslan Ermilovitself. 44973ca71feSRuslan ErmilovThe 45000c2adfeSPhilippe Charnier.Em * 45100c2adfeSPhilippe Charnieroperator sometimes yields unexpected results. 45273ca71feSRuslan ErmilovFor example, the regular expression 45373ca71feSRuslan Ermilov.Ql b* 45473ca71feSRuslan Ermilovmatches the beginning of 45573ca71feSRuslan Ermilovthe string 45673ca71feSRuslan Ermilov.Ql abbb 45773ca71feSRuslan Ermilov(as opposed to the substring 45873ca71feSRuslan Ermilov.Ql bbb ) , 45973ca71feSRuslan Ermilovsince a null match 46030154ac8SAndrew Mooreis the only left-most match. 46100c2adfeSPhilippe Charnier.It \e{n,m\e} or \e{n,\e} or \e{n\e} 46200c2adfeSPhilippe CharnierMatch the single character regular expression or subexpression 46330154ac8SAndrew Mooreimmediately preceding it at least 46400c2adfeSPhilippe Charnier.Em n 46530154ac8SAndrew Mooreand at most 46600c2adfeSPhilippe Charnier.Em m 46730154ac8SAndrew Mooretimes. 46830154ac8SAndrew MooreIf 46900c2adfeSPhilippe Charnier.Em m 47030154ac8SAndrew Mooreis omitted, then it matches at least 47100c2adfeSPhilippe Charnier.Em n 47230154ac8SAndrew Mooretimes. 47330154ac8SAndrew MooreIf the comma is also omitted, then it matches exactly 47400c2adfeSPhilippe Charnier.Em n 47530154ac8SAndrew Mooretimes. 47600c2adfeSPhilippe Charnier.El 47700c2adfeSPhilippe Charnier.Pp 47830154ac8SAndrew MooreAdditional regular expression operators may be defined depending on the 47930154ac8SAndrew Mooreparticular 48000c2adfeSPhilippe Charnier.Xr regex 3 48130154ac8SAndrew Mooreimplementation. 48200c2adfeSPhilippe Charnier.Sh COMMANDS 48330154ac8SAndrew MooreAll 48400c2adfeSPhilippe Charnier.Nm 485e3d79adaSJohn-Mark Gurneycommands are single characters, though some require additional parameters. 48630154ac8SAndrew MooreIf a command's parameters extend over several lines, then 48730154ac8SAndrew Mooreeach line except for the last 48830154ac8SAndrew Mooremust be terminated with a backslash (\\). 48912e720d7SRuslan Ermilov.Pp 49030154ac8SAndrew MooreIn general, at most one command is allowed per line. 49130154ac8SAndrew MooreHowever, most commands accept a print suffix, which is any of 49200c2adfeSPhilippe Charnier.Em p 49330154ac8SAndrew Moore(print), 49400c2adfeSPhilippe Charnier.Em l 49530154ac8SAndrew Moore(list), 49630154ac8SAndrew Mooreor 49700c2adfeSPhilippe Charnier.Em n 49830154ac8SAndrew Moore(enumerate), 49930154ac8SAndrew Mooreto print the last line affected by the command. 50012e720d7SRuslan Ermilov.Pp 50130154ac8SAndrew MooreAn interrupt (typically ^C) has the effect of aborting the current command 50230154ac8SAndrew Mooreand returning the editor to command mode. 50312e720d7SRuslan Ermilov.Pp 504e004acc8SPhilippe CharnierThe 505e004acc8SPhilippe Charnier.Nm 506e004acc8SPhilippe Charnierutility 50773ca71feSRuslan Ermilovrecognizes the following commands. 50873ca71feSRuslan ErmilovThe commands are shown together with 50930154ac8SAndrew Moorethe default address or address range supplied if none is 51030154ac8SAndrew Moorespecified (in parenthesis). 51100c2adfeSPhilippe Charnier.Bl -tag -width indent 51200c2adfeSPhilippe Charnier.It (.)a 51300c2adfeSPhilippe CharnierAppend text to the buffer after the addressed line. 51430154ac8SAndrew MooreText is entered in input mode. 51530154ac8SAndrew MooreThe current address is set to last line entered. 51600c2adfeSPhilippe Charnier.It (.,.)c 51773ca71feSRuslan ErmilovChange lines in the buffer. 51873ca71feSRuslan ErmilovThe addressed lines are deleted 51930154ac8SAndrew Moorefrom the buffer, and text is appended in their place. 52030154ac8SAndrew MooreText is entered in input mode. 52130154ac8SAndrew MooreThe current address is set to last line entered. 52200c2adfeSPhilippe Charnier.It (.,.)d 52300c2adfeSPhilippe CharnierDelete the addressed lines from the buffer. 52430154ac8SAndrew MooreIf there is a line after the deleted range, then the current address is set 525bef84d6bSSheldon Hearnto this line. 526bef84d6bSSheldon HearnOtherwise the current address is set to the line 52730154ac8SAndrew Moorebefore the deleted range. 52800c2adfeSPhilippe Charnier.It e Ar file 52900c2adfeSPhilippe CharnierEdit 53000c2adfeSPhilippe Charnier.Ar file , 53130154ac8SAndrew Mooreand sets the default filename. 53230154ac8SAndrew MooreIf 53300c2adfeSPhilippe Charnier.Ar file 53430154ac8SAndrew Mooreis not specified, then the default filename is used. 53530154ac8SAndrew MooreAny lines in the buffer are deleted before 53630154ac8SAndrew Moorethe new file is read. 53730154ac8SAndrew MooreThe current address is set to the last line read. 53800c2adfeSPhilippe Charnier.It e Ar !command 53900c2adfeSPhilippe CharnierEdit the standard output of 54000c2adfeSPhilippe Charnier.Ar !command , 54195e6217eSAndrew Moore(see 54200c2adfeSPhilippe Charnier.Ar !command 54395e6217eSAndrew Moorebelow). 54430154ac8SAndrew MooreThe default filename is unchanged. 54530154ac8SAndrew MooreAny lines in the buffer are deleted before the output of 54600c2adfeSPhilippe Charnier.Ar command 54730154ac8SAndrew Mooreis read. 54830154ac8SAndrew MooreThe current address is set to the last line read. 54900c2adfeSPhilippe Charnier.It E Ar file 55000c2adfeSPhilippe CharnierEdit 55100c2adfeSPhilippe Charnier.Ar file 55230154ac8SAndrew Mooreunconditionally. 55330154ac8SAndrew MooreThis is similar to the 55400c2adfeSPhilippe Charnier.Em e 55530154ac8SAndrew Moorecommand, 55630154ac8SAndrew Mooreexcept that unwritten changes are discarded without warning. 55730154ac8SAndrew MooreThe current address is set to the last line read. 55800c2adfeSPhilippe Charnier.It f Ar file 55900c2adfeSPhilippe CharnierSet the default filename to 56000c2adfeSPhilippe Charnier.Ar file . 56130154ac8SAndrew MooreIf 56200c2adfeSPhilippe Charnier.Ar file 56330154ac8SAndrew Mooreis not specified, then the default unescaped filename is printed. 56400c2adfeSPhilippe Charnier.It (1,$)g/re/command-list 56500c2adfeSPhilippe CharnierApply 56600c2adfeSPhilippe Charnier.Ar command-list 56730154ac8SAndrew Mooreto each of the addressed lines matching a regular expression 56800c2adfeSPhilippe Charnier.Ar re . 56930154ac8SAndrew MooreThe current address is set to the 57030154ac8SAndrew Mooreline currently matched before 57100c2adfeSPhilippe Charnier.Ar command-list 57230154ac8SAndrew Mooreis executed. 57330154ac8SAndrew MooreAt the end of the 57400c2adfeSPhilippe Charnier.Em g 57530154ac8SAndrew Moorecommand, the current address is set to the last line affected by 57600c2adfeSPhilippe Charnier.Ar command-list . 57700c2adfeSPhilippe Charnier.Pp 57830154ac8SAndrew MooreEach command in 57900c2adfeSPhilippe Charnier.Ar command-list 58030154ac8SAndrew Mooremust be on a separate line, 58130154ac8SAndrew Mooreand every line except for the last must be terminated by a backslash 58230154ac8SAndrew Moore(\\). 58330154ac8SAndrew MooreAny commands are allowed, except for 58400c2adfeSPhilippe Charnier.Em g , 58500c2adfeSPhilippe Charnier.Em G , 58600c2adfeSPhilippe Charnier.Em v , 58730154ac8SAndrew Mooreand 58800c2adfeSPhilippe Charnier.Em V . 58930154ac8SAndrew MooreA newline alone in 59000c2adfeSPhilippe Charnier.Ar command-list 59130154ac8SAndrew Mooreis equivalent to a 59200c2adfeSPhilippe Charnier.Em p 59330154ac8SAndrew Moorecommand. 59400c2adfeSPhilippe Charnier.It (1,$)G/re/ 59500c2adfeSPhilippe CharnierInteractively edit the addressed lines matching a regular expression 59600c2adfeSPhilippe Charnier.Ar re . 59730154ac8SAndrew MooreFor each matching line, 59830154ac8SAndrew Moorethe line is printed, 59930154ac8SAndrew Moorethe current address is set, 60030154ac8SAndrew Mooreand the user is prompted to enter a 60100c2adfeSPhilippe Charnier.Ar command-list . 60230154ac8SAndrew MooreAt the end of the 60300c2adfeSPhilippe Charnier.Em G 60430154ac8SAndrew Moorecommand, the current address 60530154ac8SAndrew Mooreis set to the last line affected by (the last) 60600c2adfeSPhilippe Charnier.Ar command-list . 60700c2adfeSPhilippe Charnier.Pp 60830154ac8SAndrew MooreThe format of 60900c2adfeSPhilippe Charnier.Ar command-list 61030154ac8SAndrew Mooreis the same as that of the 61100c2adfeSPhilippe Charnier.Em g 61273ca71feSRuslan Ermilovcommand. 61373ca71feSRuslan ErmilovA newline alone acts as a null command list. 61473ca71feSRuslan ErmilovA single 61573ca71feSRuslan Ermilov.Ql & 61673ca71feSRuslan Ermilovrepeats the last non-null command list. 61700c2adfeSPhilippe Charnier.It H 61800c2adfeSPhilippe CharnierToggle the printing of error explanations. 61930154ac8SAndrew MooreBy default, explanations are not printed. 62030154ac8SAndrew MooreIt is recommended that ed scripts begin with this command to 62130154ac8SAndrew Mooreaid in debugging. 62200c2adfeSPhilippe Charnier.It h 62300c2adfeSPhilippe CharnierPrint an explanation of the last error. 62400c2adfeSPhilippe Charnier.It (.)i 62500c2adfeSPhilippe CharnierInsert text in the buffer before the current line. 62630154ac8SAndrew MooreText is entered in input mode. 62730154ac8SAndrew MooreThe current address is set to the last line entered. 62800c2adfeSPhilippe Charnier.It (.,.+1)j 62973ca71feSRuslan ErmilovJoin the addressed lines. 63073ca71feSRuslan ErmilovThe addressed lines are 63130154ac8SAndrew Mooredeleted from the buffer and replaced by a single 63230154ac8SAndrew Mooreline containing their joined text. 63330154ac8SAndrew MooreThe current address is set to the resultant line. 63400c2adfeSPhilippe Charnier.It (.)klc 63500c2adfeSPhilippe CharnierMark a line with a lower case letter 63600c2adfeSPhilippe Charnier.Em lc . 63730154ac8SAndrew MooreThe line can then be addressed as 63800c2adfeSPhilippe Charnier.Em 'lc 63930154ac8SAndrew Moore(i.e., a single quote followed by 64094ba280cSRuslan Ermilov.Em lc ) 64173ca71feSRuslan Ermilovin subsequent commands. 64273ca71feSRuslan ErmilovThe mark is not cleared until the line is 64330154ac8SAndrew Mooredeleted or otherwise modified. 64400c2adfeSPhilippe Charnier.It (.,.)l 64500c2adfeSPhilippe CharnierPrint the addressed lines unambiguously. 646f68fbfedSRebecca CranIf a single line fills more than one screen (as might be the case 64773ca71feSRuslan Ermilovwhen viewing a binary file, for instance), a 64873ca71feSRuslan Ermilov.Dq Li --More-- 64995e6217eSAndrew Mooreprompt is printed on the last line. 650e004acc8SPhilippe CharnierThe 651e004acc8SPhilippe Charnier.Nm 652e004acc8SPhilippe Charnierutility waits until the RETURN key is pressed 65395e6217eSAndrew Moorebefore displaying the next screen. 65430154ac8SAndrew MooreThe current address is set to the last line 65530154ac8SAndrew Mooreprinted. 65600c2adfeSPhilippe Charnier.It (.,.)m(.) 65773ca71feSRuslan ErmilovMove lines in the buffer. 65873ca71feSRuslan ErmilovThe addressed lines are moved to after the 65930154ac8SAndrew Mooreright-hand destination address, which may be the address 66000c2adfeSPhilippe Charnier.Em 0 66130154ac8SAndrew Moore(zero). 66230154ac8SAndrew MooreThe current address is set to the 66330154ac8SAndrew Moorelast line moved. 66400c2adfeSPhilippe Charnier.It (.,.)n 66500c2adfeSPhilippe CharnierPrint the addressed lines along with 66673ca71feSRuslan Ermilovtheir line numbers. 66773ca71feSRuslan ErmilovThe current address is set to the last line 66830154ac8SAndrew Mooreprinted. 66900c2adfeSPhilippe Charnier.It (.,.)p 670bef84d6bSSheldon HearnPrint the addressed lines. 671bef84d6bSSheldon HearnThe current address is set to the last line 67230154ac8SAndrew Mooreprinted. 67300c2adfeSPhilippe Charnier.It P 67400c2adfeSPhilippe CharnierToggle the command prompt on and off. 67530154ac8SAndrew MooreUnless a prompt was specified by with command-line option 67600c2adfeSPhilippe Charnier.Fl p Ar string , 67700c2adfeSPhilippe Charnierthe command prompt is by default turned off. 67800c2adfeSPhilippe Charnier.It q 67900c2adfeSPhilippe CharnierQuit 680be8b1497SRuslan Ermilov.Nm . 68100c2adfeSPhilippe Charnier.It Q 68200c2adfeSPhilippe CharnierQuit 68300c2adfeSPhilippe Charnier.Nm 68400c2adfeSPhilippe Charnierunconditionally. 68530154ac8SAndrew MooreThis is similar to the 68600c2adfeSPhilippe Charnier.Em q 68730154ac8SAndrew Moorecommand, 68830154ac8SAndrew Mooreexcept that unwritten changes are discarded without warning. 68900c2adfeSPhilippe Charnier.It ($)r Ar file 69000c2adfeSPhilippe CharnierRead 69100c2adfeSPhilippe Charnier.Ar file 69273ca71feSRuslan Ermilovto after the addressed line. 69373ca71feSRuslan ErmilovIf 69400c2adfeSPhilippe Charnier.Ar file 69530154ac8SAndrew Mooreis not specified, then the default 69673ca71feSRuslan Ermilovfilename is used. 69773ca71feSRuslan ErmilovIf there was no default filename prior to the command, 69830154ac8SAndrew Moorethen the default filename is set to 69900c2adfeSPhilippe Charnier.Ar file . 70030154ac8SAndrew MooreOtherwise, the default filename is unchanged. 70130154ac8SAndrew MooreThe current address is set to the last line read. 70200c2adfeSPhilippe Charnier.It ($)r Ar !command 70300c2adfeSPhilippe CharnierRead 70430154ac8SAndrew Mooreto after the addressed line 70530154ac8SAndrew Moorethe standard output of 70600c2adfeSPhilippe Charnier.Ar !command , 70795e6217eSAndrew Moore(see the 70800c2adfeSPhilippe Charnier.Ar !command 70995e6217eSAndrew Moorebelow). 71030154ac8SAndrew MooreThe default filename is unchanged. 71130154ac8SAndrew MooreThe current address is set to the last line read. 71200c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/ 71300c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/g 71400c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/n 71500c2adfeSPhilippe CharnierReplace text in the addressed lines 71630154ac8SAndrew Moorematching a regular expression 71700c2adfeSPhilippe Charnier.Ar re 71830154ac8SAndrew Moorewith 71900c2adfeSPhilippe Charnier.Ar replacement . 72030154ac8SAndrew MooreBy default, only the first match in each line is replaced. 72195e6217eSAndrew MooreIf the 72200c2adfeSPhilippe Charnier.Em g 72384886bf9SWilbert Allen Koeswoyo Suwito(global) suffix is given, then every match is to be replaced. 72430154ac8SAndrew MooreThe 72500c2adfeSPhilippe Charnier.Em n 72630154ac8SAndrew Mooresuffix, where 72700c2adfeSPhilippe Charnier.Em n 72860fd953fSJordan K. Hubbardis a positive number, causes only the 72900c2adfeSPhilippe Charnier.Em n Ns th 73030154ac8SAndrew Moorematch to be replaced. 73130154ac8SAndrew MooreIt is an error if no substitutions are performed on any of the addressed 73230154ac8SAndrew Moorelines. 73330154ac8SAndrew MooreThe current address is set the last line affected. 73400c2adfeSPhilippe Charnier.Pp 7351517e564SBaptiste Daroussin.Ar \&Re 73630154ac8SAndrew Mooreand 73700c2adfeSPhilippe Charnier.Ar replacement 73895e6217eSAndrew Mooremay be delimited by any character other than space and newline 73995e6217eSAndrew Moore(see the 74000c2adfeSPhilippe Charnier.Em s 74195e6217eSAndrew Moorecommand below). 74230154ac8SAndrew MooreIf one or two of the last delimiters is omitted, then the last line 74330154ac8SAndrew Mooreaffected is printed as though the print suffix 74400c2adfeSPhilippe Charnier.Em p 74530154ac8SAndrew Moorewere specified. 74600c2adfeSPhilippe Charnier.Pp 74773ca71feSRuslan ErmilovAn unescaped 74873ca71feSRuslan Ermilov.Ql & 74973ca71feSRuslan Ermilovin 75000c2adfeSPhilippe Charnier.Ar replacement 75130154ac8SAndrew Mooreis replaced by the currently matched text. 75230154ac8SAndrew MooreThe character sequence 75300c2adfeSPhilippe Charnier.Em \em , 75430154ac8SAndrew Moorewhere 75500c2adfeSPhilippe Charnier.Em m 75630154ac8SAndrew Mooreis a number in the range [1,9], is replaced by the 75700c2adfeSPhilippe Charnier.Em m th 75830154ac8SAndrew Moorebackreference expression of the matched text. 75930154ac8SAndrew MooreIf 76000c2adfeSPhilippe Charnier.Ar replacement 76173ca71feSRuslan Ermilovconsists of a single 76273ca71feSRuslan Ermilov.Ql % , 76373ca71feSRuslan Ermilovthen 76400c2adfeSPhilippe Charnier.Ar replacement 76530154ac8SAndrew Moorefrom the last substitution is used. 76630154ac8SAndrew MooreNewlines may be embedded in 76700c2adfeSPhilippe Charnier.Ar replacement 76830154ac8SAndrew Mooreif they are escaped with a backslash (\\). 76900c2adfeSPhilippe Charnier.It (.,.)s 77000c2adfeSPhilippe CharnierRepeat the last substitution. 77130154ac8SAndrew MooreThis form of the 77200c2adfeSPhilippe Charnier.Em s 77395e6217eSAndrew Moorecommand accepts a count suffix 77400c2adfeSPhilippe Charnier.Em n , 77595e6217eSAndrew Mooreor any combination of the characters 77600c2adfeSPhilippe Charnier.Em r , 77700c2adfeSPhilippe Charnier.Em g , 77830154ac8SAndrew Mooreand 77900c2adfeSPhilippe Charnier.Em p . 78095e6217eSAndrew MooreIf a count suffix 78100c2adfeSPhilippe Charnier.Em n 78295e6217eSAndrew Mooreis given, then only the 78300c2adfeSPhilippe Charnier.Em n Ns th 78495e6217eSAndrew Moorematch is replaced. 78530154ac8SAndrew MooreThe 78600c2adfeSPhilippe Charnier.Em r 78730154ac8SAndrew Mooresuffix causes 78830154ac8SAndrew Moorethe regular expression of the last search to be used instead of the 78930154ac8SAndrew Moorethat of the last substitution. 79030154ac8SAndrew MooreThe 79100c2adfeSPhilippe Charnier.Em g 79230154ac8SAndrew Mooresuffix toggles the global suffix of the last substitution. 79330154ac8SAndrew MooreThe 79400c2adfeSPhilippe Charnier.Em p 79530154ac8SAndrew Mooresuffix toggles the print suffix of the last substitution 79630154ac8SAndrew MooreThe current address is set to the last line affected. 79700c2adfeSPhilippe Charnier.It (.,.)t(.) 79800c2adfeSPhilippe CharnierCopy (i.e., transfer) the addressed lines to after the right-hand 79930154ac8SAndrew Mooredestination address, which may be the address 80000c2adfeSPhilippe Charnier.Em 0 80130154ac8SAndrew Moore(zero). 80230154ac8SAndrew MooreThe current address is set to the last line 80330154ac8SAndrew Moorecopied. 80400c2adfeSPhilippe Charnier.It u 80500c2adfeSPhilippe CharnierUndo the last command and restores the current address 80630154ac8SAndrew Mooreto what it was before the command. 80730154ac8SAndrew MooreThe global commands 80800c2adfeSPhilippe Charnier.Em g , 80900c2adfeSPhilippe Charnier.Em G , 81000c2adfeSPhilippe Charnier.Em v , 81130154ac8SAndrew Mooreand 81200c2adfeSPhilippe Charnier.Em V . 81330154ac8SAndrew Mooreare treated as a single command by undo. 81400c2adfeSPhilippe Charnier.Em u 81530154ac8SAndrew Mooreis its own inverse. 81600c2adfeSPhilippe Charnier.It (1,$)v/re/command-list 81700c2adfeSPhilippe CharnierApply 81800c2adfeSPhilippe Charnier.Ar command-list 81930154ac8SAndrew Mooreto each of the addressed lines not matching a regular expression 82000c2adfeSPhilippe Charnier.Ar re . 82130154ac8SAndrew MooreThis is similar to the 82200c2adfeSPhilippe Charnier.Em g 82330154ac8SAndrew Moorecommand. 82400c2adfeSPhilippe Charnier.It (1,$)V/re/ 82500c2adfeSPhilippe CharnierInteractively edit the addressed lines not matching a regular expression 82600c2adfeSPhilippe Charnier.Ar re . 82730154ac8SAndrew MooreThis is similar to the 82800c2adfeSPhilippe Charnier.Em G 82930154ac8SAndrew Moorecommand. 83000c2adfeSPhilippe Charnier.It (1,$)w Ar file 83100c2adfeSPhilippe CharnierWrite the addressed lines to 83200c2adfeSPhilippe Charnier.Ar file . 83330154ac8SAndrew MooreAny previous contents of 83400c2adfeSPhilippe Charnier.Ar file 83584886bf9SWilbert Allen Koeswoyo Suwitoare lost without warning. 83630154ac8SAndrew MooreIf there is no default filename, then the default filename is set to 83700c2adfeSPhilippe Charnier.Ar file , 83873ca71feSRuslan Ermilovotherwise it is unchanged. 83973ca71feSRuslan ErmilovIf no filename is specified, then the default 84030154ac8SAndrew Moorefilename is used. 84130154ac8SAndrew MooreThe current address is unchanged. 84200c2adfeSPhilippe Charnier.It (1,$)wq Ar file 84300c2adfeSPhilippe CharnierWrite the addressed lines to 84400c2adfeSPhilippe Charnier.Ar file , 84530154ac8SAndrew Mooreand then executes a 84600c2adfeSPhilippe Charnier.Em q 84730154ac8SAndrew Moorecommand. 84800c2adfeSPhilippe Charnier.It (1,$)w Ar !command 84900c2adfeSPhilippe CharnierWrite the addressed lines to the standard input of 85000c2adfeSPhilippe Charnier.Ar !command , 85195e6217eSAndrew Moore(see the 85200c2adfeSPhilippe Charnier.Em !command 85395e6217eSAndrew Moorebelow). 85430154ac8SAndrew MooreThe default filename and current address are unchanged. 85500c2adfeSPhilippe Charnier.It (1,$)W Ar file 85600c2adfeSPhilippe CharnierAppend the addressed lines to the end of 85700c2adfeSPhilippe Charnier.Ar file . 85830154ac8SAndrew MooreThis is similar to the 85900c2adfeSPhilippe Charnier.Em w 86030154ac8SAndrew Moorecommand, expect that the previous contents of file is not clobbered. 86130154ac8SAndrew MooreThe current address is unchanged. 86200c2adfeSPhilippe Charnier.It Pf (.+1)z n 86300c2adfeSPhilippe CharnierScroll 86400c2adfeSPhilippe Charnier.Ar n 86573ca71feSRuslan Ermilovlines at a time starting at addressed line. 86673ca71feSRuslan ErmilovIf 86700c2adfeSPhilippe Charnier.Ar n 86830154ac8SAndrew Mooreis not specified, then the current window size is used. 86930154ac8SAndrew MooreThe current address is set to the last line printed. 87000c2adfeSPhilippe Charnier.It !command 87100c2adfeSPhilippe CharnierExecute 87200c2adfeSPhilippe Charnier.Ar command 87330154ac8SAndrew Moorevia 87400c2adfeSPhilippe Charnier.Xr sh 1 . 87530154ac8SAndrew MooreIf the first character of 87600c2adfeSPhilippe Charnier.Ar command 87773ca71feSRuslan Ermilovis 87873ca71feSRuslan Ermilov.Ql \&! , 87973ca71feSRuslan Ermilovthen it is replaced by text of the 88030154ac8SAndrew Mooreprevious 88100c2adfeSPhilippe Charnier.Ar !command . 882e004acc8SPhilippe CharnierThe 883e004acc8SPhilippe Charnier.Nm 884e004acc8SPhilippe Charnierutility does not process 88500c2adfeSPhilippe Charnier.Ar command 88630154ac8SAndrew Moorefor backslash (\\) escapes. 88730154ac8SAndrew MooreHowever, an unescaped 88800c2adfeSPhilippe Charnier.Em % 88930154ac8SAndrew Mooreis replaced by the default filename. 89073ca71feSRuslan ErmilovWhen the shell returns from execution, a 89173ca71feSRuslan Ermilov.Ql \&! 89230154ac8SAndrew Mooreis printed to the standard output. 89330154ac8SAndrew MooreThe current line is unchanged. 89400c2adfeSPhilippe Charnier.It ($)= 89500c2adfeSPhilippe CharnierPrint the line number of the addressed line. 89600c2adfeSPhilippe Charnier.It (.+1)newline 89700c2adfeSPhilippe CharnierPrint the addressed line, and sets the current address to 89830154ac8SAndrew Moorethat line. 89900c2adfeSPhilippe Charnier.El 90000c2adfeSPhilippe Charnier.Sh FILES 90100c2adfeSPhilippe Charnier.Bl -tag -width /tmp/ed.* -compact 9022710751bSJoel Dahl.It Pa /tmp/ed.* 90300c2adfeSPhilippe Charnierbuffer file 9042710751bSJoel Dahl.It Pa ed.hup 90500c2adfeSPhilippe Charnierthe file to which 90600c2adfeSPhilippe Charnier.Nm 90700c2adfeSPhilippe Charnierattempts to write the buffer if the terminal hangs up 90800c2adfeSPhilippe Charnier.El 90900c2adfeSPhilippe Charnier.Sh DIAGNOSTICS 91030154ac8SAndrew MooreWhen an error occurs, 91100c2adfeSPhilippe Charnier.Nm 91273ca71feSRuslan Ermilovprints a 91373ca71feSRuslan Ermilov.Ql \&? 91473ca71feSRuslan Ermilovand either returns to command mode 91530154ac8SAndrew Mooreor exits if its input is from a script. 91630154ac8SAndrew MooreAn explanation of the last error can be 91730154ac8SAndrew Mooreprinted with the 91800c2adfeSPhilippe Charnier.Em h 91930154ac8SAndrew Moore(help) command. 92012e720d7SRuslan Ermilov.Pp 92130154ac8SAndrew MooreSince the 92200c2adfeSPhilippe Charnier.Em g 92330154ac8SAndrew Moore(global) command masks any errors from failed searches and substitutions, 92430154ac8SAndrew Mooreit can be used to perform conditional operations in scripts; e.g., 92500c2adfeSPhilippe Charnier.Pp 92600c2adfeSPhilippe Charnier.Sm off 92700c2adfeSPhilippe Charnier.Cm g No / Em old Xo 92800c2adfeSPhilippe Charnier.No / Cm s 92900c2adfeSPhilippe Charnier.No // Em new 93000c2adfeSPhilippe Charnier.No / 93100c2adfeSPhilippe Charnier.Xc 93200c2adfeSPhilippe Charnier.Sm on 93300c2adfeSPhilippe Charnier.Pp 93430154ac8SAndrew Moorereplaces any occurrences of 93500c2adfeSPhilippe Charnier.Em old 93630154ac8SAndrew Moorewith 93700c2adfeSPhilippe Charnier.Em new . 93810ca1c6cSAndrew MooreIf the 93900c2adfeSPhilippe Charnier.Em u 94010ca1c6cSAndrew Moore(undo) command occurs in a global command list, then 94110ca1c6cSAndrew Moorethe command list is executed only once. 94212e720d7SRuslan Ermilov.Pp 94330154ac8SAndrew MooreIf diagnostics are not disabled, attempting to quit 94400c2adfeSPhilippe Charnier.Nm 94530154ac8SAndrew Mooreor edit another file before writing a modified buffer 94630154ac8SAndrew Mooreresults in an error. 94730154ac8SAndrew MooreIf the command is entered a second time, it succeeds, 94830154ac8SAndrew Moorebut any changes to the buffer are lost. 9496fca4c7cSRuslan Ermilov.Sh SEE ALSO 9506fca4c7cSRuslan Ermilov.Xr sed 1 , 9516fca4c7cSRuslan Ermilov.Xr sh 1 , 9526fca4c7cSRuslan Ermilov.Xr vi 1 , 9536fca4c7cSRuslan Ermilov.Xr regex 3 9546fca4c7cSRuslan Ermilov.Pp 9556fca4c7cSRuslan ErmilovUSD:12-13 9566fca4c7cSRuslan Ermilov.Rs 9576fca4c7cSRuslan Ermilov.%A B. W. Kernighan 9586fca4c7cSRuslan Ermilov.%A P. J. Plauger 9596fca4c7cSRuslan Ermilov.%B Software Tools in Pascal 9606fca4c7cSRuslan Ermilov.%O Addison-Wesley 9616fca4c7cSRuslan Ermilov.%D 1981 9626fca4c7cSRuslan Ermilov.Re 9633ce57932SGordon Bergling.Rs 9643ce57932SGordon Bergling.\" 4.4BSD USD:9 9653ce57932SGordon Bergling.%A B. W. Kernighan 9663ce57932SGordon Bergling.%T A Tutorial Introduction to the UNIX Text Editor 9673ce57932SGordon Bergling.Re 9683ce57932SGordon Bergling.Rs 9693ce57932SGordon Bergling.\" 4.4BSD USD:10 9703ce57932SGordon Bergling.%A B. W. Kernighan 9713ce57932SGordon Bergling.%T Advanced Editing on UNIX 9723ce57932SGordon Bergling.Re 9736fca4c7cSRuslan Ermilov.Sh LIMITATIONS 9746fca4c7cSRuslan ErmilovThe 9756fca4c7cSRuslan Ermilov.Nm 9766fca4c7cSRuslan Ermilovutility processes 9776fca4c7cSRuslan Ermilov.Ar file 9786fca4c7cSRuslan Ermilovarguments for backslash escapes, i.e., in a filename, 9796fca4c7cSRuslan Ermilovany characters preceded by a backslash (\\) are 9806fca4c7cSRuslan Ermilovinterpreted literally. 9816fca4c7cSRuslan Ermilov.Pp 9826fca4c7cSRuslan ErmilovIf a text (non-binary) file is not terminated by a newline character, 9836fca4c7cSRuslan Ermilovthen 9846fca4c7cSRuslan Ermilov.Nm 9856fca4c7cSRuslan Ermilovappends one on reading/writing it. 9866fca4c7cSRuslan ErmilovIn the case of a binary file, 9876fca4c7cSRuslan Ermilov.Nm 9886fca4c7cSRuslan Ermilovdoes not append a newline on reading/writing. 9896fca4c7cSRuslan Ermilov.Pp 9906fca4c7cSRuslan Ermilovper line overhead: 4 ints 99100c2adfeSPhilippe Charnier.Sh HISTORY 9929076772fSDima DorfmanAn 99300c2adfeSPhilippe Charnier.Nm 994b8923d4cSWolfram Schneidercommand appeared in 995bc799c51SSevan Janiyan.At v1 . 996128dc4a2STim J. Robbins.Sh BUGS 997128dc4a2STim J. RobbinsThe 998128dc4a2STim J. Robbins.Nm 999128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 1000