12a456239SPeter Wemm.\" $FreeBSD$ 2bc799c51SSevan Janiyan.Dd October 2, 2016 300c2adfeSPhilippe Charnier.Dt ED 1 400c2adfeSPhilippe Charnier.Os 500c2adfeSPhilippe Charnier.Sh NAME 6daa40efdSAlexey Zelkin.Nm ed , 7daa40efdSAlexey Zelkin.Nm red 800c2adfeSPhilippe Charnier.Nd text editor 900c2adfeSPhilippe Charnier.Sh SYNOPSIS 10be8b1497SRuslan Ermilov.Nm 1100c2adfeSPhilippe Charnier.Op Fl 1200c2adfeSPhilippe Charnier.Op Fl sx 1300c2adfeSPhilippe Charnier.Op Fl p Ar string 1400c2adfeSPhilippe Charnier.Op Ar file 1509152a86SGiorgos Keramidas.Nm red 1609152a86SGiorgos Keramidas.Op Fl 1709152a86SGiorgos Keramidas.Op Fl sx 1809152a86SGiorgos Keramidas.Op Fl p Ar string 1909152a86SGiorgos Keramidas.Op Ar file 2000c2adfeSPhilippe Charnier.Sh DESCRIPTION 21e004acc8SPhilippe CharnierThe 22e004acc8SPhilippe Charnier.Nm 23e004acc8SPhilippe Charnierutility is a line-oriented text editor. 2430154ac8SAndrew MooreIt is used to create, display, modify and otherwise manipulate text 2530154ac8SAndrew Moorefiles. 2609152a86SGiorgos KeramidasWhen invoked as 2709152a86SGiorgos Keramidas.Nm red , 2809152a86SGiorgos Keramidasthe editor runs in 2909152a86SGiorgos Keramidas.Qq restricted 3009152a86SGiorgos Keramidasmode, in which the only difference is that the editor restricts the 3109152a86SGiorgos Keramidasuse of filenames which start with 3209152a86SGiorgos Keramidas.Ql \&! 3309152a86SGiorgos Keramidas(interpreted as shell commands by 3473ca71feSRuslan Ermilov.Nm ) 3509152a86SGiorgos Keramidasor contain a 3609152a86SGiorgos Keramidas.Ql \&/ . 3709152a86SGiorgos KeramidasNote that editing outside of the current directory is only prohibited 3809152a86SGiorgos Keramidasif the user does not have write access to the current directory. 3909152a86SGiorgos KeramidasIf a user has write access to the current directory, then symbolic 4009152a86SGiorgos Keramidaslinks can be created in the current directory, in which case 4109152a86SGiorgos Keramidas.Nm red 4209152a86SGiorgos Keramidaswill not stop the user from editing the file that the symbolic link 4309152a86SGiorgos Keramidaspoints to. 4412e720d7SRuslan Ermilov.Pp 4530154ac8SAndrew MooreIf invoked with a 4600c2adfeSPhilippe Charnier.Ar file 4730154ac8SAndrew Mooreargument, then a copy of 4800c2adfeSPhilippe Charnier.Ar file 4930154ac8SAndrew Mooreis read into the editor's buffer. 5030154ac8SAndrew MooreChanges are made to this copy and not directly to 5100c2adfeSPhilippe Charnier.Ar file 5230154ac8SAndrew Mooreitself. 5330154ac8SAndrew MooreUpon quitting 54be8b1497SRuslan Ermilov.Nm , 5530154ac8SAndrew Mooreany changes not explicitly saved with a 5600c2adfeSPhilippe Charnier.Em w 5730154ac8SAndrew Moorecommand are lost. 5812e720d7SRuslan Ermilov.Pp 5930154ac8SAndrew MooreEditing is done in two distinct modes: 6000c2adfeSPhilippe Charnier.Em command 6130154ac8SAndrew Mooreand 6200c2adfeSPhilippe Charnier.Em input . 6330154ac8SAndrew MooreWhen first invoked, 6400c2adfeSPhilippe Charnier.Nm 6530154ac8SAndrew Mooreis in command mode. 6630154ac8SAndrew MooreIn this mode commands are read from the standard input and 6730154ac8SAndrew Mooreexecuted to manipulate the contents of the editor buffer. 6830154ac8SAndrew MooreA typical command might look like: 6900c2adfeSPhilippe Charnier.Pp 7000c2adfeSPhilippe Charnier.Sm off 7100c2adfeSPhilippe Charnier.Cm ,s No / Em old Xo 7200c2adfeSPhilippe Charnier.No / Em new 7300c2adfeSPhilippe Charnier.No / Cm g 7400c2adfeSPhilippe Charnier.Xc 7500c2adfeSPhilippe Charnier.Sm on 7600c2adfeSPhilippe Charnier.Pp 7760fd953fSJordan K. Hubbardwhich replaces all occurrences of the string 7800c2adfeSPhilippe Charnier.Em old 7930154ac8SAndrew Moorewith 8000c2adfeSPhilippe Charnier.Em new . 8100c2adfeSPhilippe Charnier.Pp 8230154ac8SAndrew MooreWhen an input command, such as 8300c2adfeSPhilippe Charnier.Em a 8430154ac8SAndrew Moore(append), 8500c2adfeSPhilippe Charnier.Em i 8630154ac8SAndrew Moore(insert) or 8700c2adfeSPhilippe Charnier.Em c 8830154ac8SAndrew Moore(change), is given, 8900c2adfeSPhilippe Charnier.Nm 9073ca71feSRuslan Ermiloventers input mode. 9173ca71feSRuslan ErmilovThis is the primary means 9230154ac8SAndrew Mooreof adding text to a file. 9330154ac8SAndrew MooreIn this mode, no commands are available; 9430154ac8SAndrew Mooreinstead, the standard input is written 9573ca71feSRuslan Ermilovdirectly to the editor buffer. 9673ca71feSRuslan ErmilovLines consist of text up to and 9730154ac8SAndrew Mooreincluding a 9800c2adfeSPhilippe Charnier.Em newline 9930154ac8SAndrew Moorecharacter. 10030154ac8SAndrew MooreInput mode is terminated by 10100c2adfeSPhilippe Charnierentering a single period 10212e720d7SRuslan Ermilov.Pq Em .\& 10300c2adfeSPhilippe Charnieron a line. 10400c2adfeSPhilippe Charnier.Pp 10530154ac8SAndrew MooreAll 10600c2adfeSPhilippe Charnier.Nm 10730154ac8SAndrew Moorecommands operate on whole lines or ranges of lines; e.g., 10830154ac8SAndrew Moorethe 10900c2adfeSPhilippe Charnier.Em d 11030154ac8SAndrew Moorecommand deletes lines; the 11100c2adfeSPhilippe Charnier.Em m 11230154ac8SAndrew Moorecommand moves lines, and so on. 11330154ac8SAndrew MooreIt is possible to modify only a portion of a line by means of replacement, 11473ca71feSRuslan Ermilovas in the example above. 11573ca71feSRuslan ErmilovHowever even here, the 11600c2adfeSPhilippe Charnier.Em s 11730154ac8SAndrew Moorecommand is applied to whole lines at a time. 11800c2adfeSPhilippe Charnier.Pp 11930154ac8SAndrew MooreIn general, 12000c2adfeSPhilippe Charnier.Nm 12130154ac8SAndrew Moorecommands consist of zero or more line addresses, followed by a single 12230154ac8SAndrew Moorecharacter command and possibly additional parameters; i.e., 12330154ac8SAndrew Moorecommands have the structure: 12400c2adfeSPhilippe Charnier.Pp 12500c2adfeSPhilippe Charnier.Sm off 126d0353b83SRuslan Ermilov.Xo 127d0353b83SRuslan Ermilov.Op Ar address Op , Ar address 128d0353b83SRuslan Ermilov.Ar command Op Ar parameters 12900c2adfeSPhilippe Charnier.Xc 13000c2adfeSPhilippe Charnier.Sm on 13100c2adfeSPhilippe Charnier.Pp 13210ca1c6cSAndrew MooreThe address(es) indicate the line or range of lines to be affected by the 13373ca71feSRuslan Ermilovcommand. 13473ca71feSRuslan ErmilovIf fewer addresses are given than the command accepts, then 13510ca1c6cSAndrew Mooredefault addresses are supplied. 13600c2adfeSPhilippe Charnier.Sh OPTIONS 13700c2adfeSPhilippe CharnierThe following options are available: 13800c2adfeSPhilippe Charnier.Bl -tag -width indent 13900c2adfeSPhilippe Charnier.It Fl s 140bef84d6bSSheldon HearnSuppress diagnostics. 141bef84d6bSSheldon HearnThis should be used if 14200c2adfeSPhilippe Charnier.Nm Ns 's 14330154ac8SAndrew Moorestandard input is from a script. 14400c2adfeSPhilippe Charnier.It Fl x 14500c2adfeSPhilippe CharnierPrompt for an encryption key to be used in subsequent reads and writes 14630154ac8SAndrew Moore(see the 14700c2adfeSPhilippe Charnier.Em x 14830154ac8SAndrew Moorecommand). 14900c2adfeSPhilippe Charnier.It Fl p Ar string 15073ca71feSRuslan ErmilovSpecify a command prompt. 15173ca71feSRuslan ErmilovThis may be toggled on and off with the 15200c2adfeSPhilippe Charnier.Em P 15330154ac8SAndrew Moorecommand. 15400c2adfeSPhilippe Charnier.It Ar file 15573ca71feSRuslan ErmilovSpecify the name of a file to read. 15673ca71feSRuslan ErmilovIf 15700c2adfeSPhilippe Charnier.Ar file 15830154ac8SAndrew Mooreis prefixed with a 15973ca71feSRuslan Ermilovbang (!), then it is interpreted as a shell command. 16073ca71feSRuslan ErmilovIn this case, 16130154ac8SAndrew Moorewhat is read is 16230154ac8SAndrew Moorethe standard output of 16300c2adfeSPhilippe Charnier.Ar file 16430154ac8SAndrew Mooreexecuted via 16500c2adfeSPhilippe Charnier.Xr sh 1 . 16630154ac8SAndrew MooreTo read a file whose name begins with a bang, prefix the 16730154ac8SAndrew Moorename with a backslash (\\). 16830154ac8SAndrew MooreThe default filename is set to 16900c2adfeSPhilippe Charnier.Ar file 17030154ac8SAndrew Mooreonly if it is not prefixed with a bang. 17100c2adfeSPhilippe Charnier.El 17200c2adfeSPhilippe Charnier.Sh LINE ADDRESSING 17395e6217eSAndrew MooreAn address represents the number of a line in the buffer. 174e004acc8SPhilippe CharnierThe 175e004acc8SPhilippe Charnier.Nm 176e004acc8SPhilippe Charnierutility maintains a 17700c2adfeSPhilippe Charnier.Em current address 17830154ac8SAndrew Moorewhich is 17930154ac8SAndrew Mooretypically supplied to commands as the default address when none is specified. 18030154ac8SAndrew MooreWhen a file is first read, the current address is set to the last line 18173ca71feSRuslan Ermilovof the file. 18273ca71feSRuslan ErmilovIn general, the current address is set to the last line 18330154ac8SAndrew Mooreaffected by a command. 18400c2adfeSPhilippe Charnier.Pp 18530154ac8SAndrew MooreA line address is 18630154ac8SAndrew Mooreconstructed from one of the bases in the list below, optionally followed 18773ca71feSRuslan Ermilovby a numeric offset. 18873ca71feSRuslan ErmilovThe offset may include any combination 18930154ac8SAndrew Mooreof digits, operators (i.e., 19000c2adfeSPhilippe Charnier.Em + , 19100c2adfeSPhilippe Charnier.Em - 19230154ac8SAndrew Mooreand 19300c2adfeSPhilippe Charnier.Em ^ ) 19430154ac8SAndrew Mooreand whitespace. 19530154ac8SAndrew MooreAddresses are read from left to right, and their values are computed 19630154ac8SAndrew Moorerelative to the current address. 19700c2adfeSPhilippe Charnier.Pp 19830154ac8SAndrew MooreOne exception to the rule that addresses represent line numbers is the 19930154ac8SAndrew Mooreaddress 20000c2adfeSPhilippe Charnier.Em 0 20130154ac8SAndrew Moore(zero). 20230154ac8SAndrew MooreThis means "before the first line," 20330154ac8SAndrew Mooreand is legal wherever it makes sense. 20400c2adfeSPhilippe Charnier.Pp 20530154ac8SAndrew MooreAn address range is two addresses separated either by a comma or 206bef84d6bSSheldon Hearnsemi-colon. 207bef84d6bSSheldon HearnThe value of the first address in a range cannot exceed the 20873ca71feSRuslan Ermilovvalue of the second. 20973ca71feSRuslan ErmilovIf only one address is given in a range, then 21073ca71feSRuslan Ermilovthe second address is set to the given address. 21173ca71feSRuslan ErmilovIf an 21200c2adfeSPhilippe Charnier.Em n Ns -tuple 21330154ac8SAndrew Mooreof addresses is given where 21400c2adfeSPhilippe Charnier.Em "n\ >\ 2" , 21595e6217eSAndrew Moorethen the corresponding range is determined by the last two addresses in 21695e6217eSAndrew Moorethe 21700c2adfeSPhilippe Charnier.Em n Ns -tuple . 21895e6217eSAndrew MooreIf only one address is expected, then the last address is used. 21900c2adfeSPhilippe Charnier.Pp 22030154ac8SAndrew MooreEach address in a comma-delimited range is interpreted relative to the 22173ca71feSRuslan Ermilovcurrent address. 22273ca71feSRuslan ErmilovIn a semi-colon-delimited range, the first address is 22330154ac8SAndrew Mooreused to set the current address, and the second address is interpreted 22430154ac8SAndrew Moorerelative to the first. 22500c2adfeSPhilippe Charnier.Pp 22600c2adfeSPhilippe CharnierThe following address symbols are recognized: 22700c2adfeSPhilippe Charnier.Bl -tag -width indent 22800c2adfeSPhilippe Charnier.It . 22930154ac8SAndrew MooreThe current line (address) in the buffer. 23000c2adfeSPhilippe Charnier.It $ 23130154ac8SAndrew MooreThe last line in the buffer. 23200c2adfeSPhilippe Charnier.It n 23330154ac8SAndrew MooreThe 234f68fbfedSRebecca Cran.Em n Ns th 23530154ac8SAndrew Mooreline in the buffer 23630154ac8SAndrew Moorewhere 23700c2adfeSPhilippe Charnier.Em n 23830154ac8SAndrew Mooreis a number in the range 23900c2adfeSPhilippe Charnier.Em [0,$] . 24000c2adfeSPhilippe Charnier.It - or ^ 24130154ac8SAndrew MooreThe previous line. 24230154ac8SAndrew MooreThis is equivalent to 24300c2adfeSPhilippe Charnier.Em -1 24430154ac8SAndrew Mooreand may be repeated with cumulative effect. 24500c2adfeSPhilippe Charnier.It -n or ^n 24630154ac8SAndrew MooreThe 24700c2adfeSPhilippe Charnier.Em n Ns th 24830154ac8SAndrew Mooreprevious line, where 24900c2adfeSPhilippe Charnier.Em n 25030154ac8SAndrew Mooreis a non-negative number. 25100c2adfeSPhilippe Charnier.It + 25200c2adfeSPhilippe CharnierThe next line. 25330154ac8SAndrew MooreThis is equivalent to 25400c2adfeSPhilippe Charnier.Em +1 25530154ac8SAndrew Mooreand may be repeated with cumulative effect. 256056103b6SJoseph Koshy.It +n 25730154ac8SAndrew MooreThe 25800c2adfeSPhilippe Charnier.Em n Ns th 25930154ac8SAndrew Moorenext line, where 26000c2adfeSPhilippe Charnier.Em n 26130154ac8SAndrew Mooreis a non-negative number. 26200c2adfeSPhilippe Charnier.It , or % 26373ca71feSRuslan ErmilovThe first through last lines in the buffer. 26473ca71feSRuslan ErmilovThis is equivalent to 26530154ac8SAndrew Moorethe address range 26600c2adfeSPhilippe Charnier.Em 1,$ . 26700c2adfeSPhilippe Charnier.It ; 26873ca71feSRuslan ErmilovThe current through last lines in the buffer. 26973ca71feSRuslan ErmilovThis is equivalent to 27030154ac8SAndrew Moorethe address range 27100c2adfeSPhilippe Charnier.Em .,$ . 27200c2adfeSPhilippe Charnier.It /re/ 27300c2adfeSPhilippe CharnierThe next line containing the regular expression 27400c2adfeSPhilippe Charnier.Em re . 27530154ac8SAndrew MooreThe search wraps to the beginning of the buffer and continues down to the 27630154ac8SAndrew Moorecurrent line, if necessary. 27730154ac8SAndrew Moore// repeats the last search. 27800c2adfeSPhilippe Charnier.It ?re? 27930154ac8SAndrew MooreThe 28030154ac8SAndrew Mooreprevious line containing the regular expression 28100c2adfeSPhilippe Charnier.Em re . 28230154ac8SAndrew MooreThe search wraps to the end of the buffer and continues up to the 28330154ac8SAndrew Moorecurrent line, if necessary. 28430154ac8SAndrew Moore?? repeats the last search. 28500c2adfeSPhilippe Charnier.It 'lc 28630154ac8SAndrew MooreThe 28730154ac8SAndrew Mooreline previously marked by a 28800c2adfeSPhilippe Charnier.Em k 28930154ac8SAndrew Moore(mark) command, where 29000c2adfeSPhilippe Charnier.Em lc 29130154ac8SAndrew Mooreis a lower case letter. 29200c2adfeSPhilippe Charnier.El 29300c2adfeSPhilippe Charnier.Sh REGULAR EXPRESSIONS 29430154ac8SAndrew MooreRegular expressions are patterns used in selecting text. 29500c2adfeSPhilippe CharnierFor example, the command: 29600c2adfeSPhilippe Charnier.Pp 29700c2adfeSPhilippe Charnier.Sm off 29800c2adfeSPhilippe Charnier.Cm g No / Em string Xo 29900c2adfeSPhilippe Charnier.No / 30000c2adfeSPhilippe Charnier.Xc 30100c2adfeSPhilippe Charnier.Sm on 30200c2adfeSPhilippe Charnier.Pp 30330154ac8SAndrew Mooreprints all lines containing 30400c2adfeSPhilippe Charnier.Em string . 30530154ac8SAndrew MooreRegular expressions are also 30630154ac8SAndrew Mooreused by the 30700c2adfeSPhilippe Charnier.Em s 30830154ac8SAndrew Moorecommand for selecting old text to be replaced with new. 30900c2adfeSPhilippe Charnier.Pp 31030154ac8SAndrew MooreIn addition to a specifying string literals, regular expressions can 31130154ac8SAndrew Moorerepresent 31273ca71feSRuslan Ermilovclasses of strings. 31373ca71feSRuslan ErmilovStrings thus represented are said to be matched 31430154ac8SAndrew Mooreby the corresponding regular expression. 31530154ac8SAndrew MooreIf it is possible for a regular expression 31630154ac8SAndrew Mooreto match several strings in a line, then the left-most longest match is 31730154ac8SAndrew Moorethe one selected. 31800c2adfeSPhilippe Charnier.Pp 31930154ac8SAndrew MooreThe following symbols are used in constructing regular expressions: 32000c2adfeSPhilippe Charnier.Bl -tag -width indent 32100c2adfeSPhilippe Charnier.It c 32230154ac8SAndrew MooreAny character 32300c2adfeSPhilippe Charnier.Em c 32473ca71feSRuslan Ermilovnot listed below, including 32573ca71feSRuslan Ermilov.Ql \&{ , 32673ca71feSRuslan Ermilov.Ql \&} , 32773ca71feSRuslan Ermilov.Ql \&( , 32873ca71feSRuslan Ermilov.Ql \&) , 32973ca71feSRuslan Ermilov.Ql < 33073ca71feSRuslan Ermilovand 33173ca71feSRuslan Ermilov.Ql > , 33230154ac8SAndrew Moorematches itself. 33300c2adfeSPhilippe Charnier.It Pf \e c 33430154ac8SAndrew MooreAny backslash-escaped character 33500c2adfeSPhilippe Charnier.Em c , 33673ca71feSRuslan Ermilovexcept for 33773ca71feSRuslan Ermilov.Ql \&{ , 33873ca71feSRuslan Ermilov.Ql \&} , 33973ca71feSRuslan Ermilov.Ql \&( , 34073ca71feSRuslan Ermilov.Ql \&) , 34173ca71feSRuslan Ermilov.Ql < 34273ca71feSRuslan Ermilovand 34373ca71feSRuslan Ermilov.Ql > , 34430154ac8SAndrew Moorematches itself. 34500c2adfeSPhilippe Charnier.It . 34600c2adfeSPhilippe CharnierMatch any single character. 34700c2adfeSPhilippe Charnier.It Op char-class 34800c2adfeSPhilippe CharnierMatch any single character in 34900c2adfeSPhilippe Charnier.Em char-class . 35073ca71feSRuslan ErmilovTo include a 35173ca71feSRuslan Ermilov.Ql \&] 35230154ac8SAndrew Moorein 35300c2adfeSPhilippe Charnier.Em char-class , 35430154ac8SAndrew Mooreit must be the first character. 35530154ac8SAndrew MooreA range of characters may be specified by separating the end characters 35673ca71feSRuslan Ermilovof the range with a 35773ca71feSRuslan Ermilov.Ql - , 35873ca71feSRuslan Ermilove.g., 35973ca71feSRuslan Ermilov.Ql a-z 36073ca71feSRuslan Ermilovspecifies the lower case characters. 36130154ac8SAndrew MooreThe following literal expressions can also be used in 36200c2adfeSPhilippe Charnier.Em char-class 36330154ac8SAndrew Mooreto specify sets of characters: 36400c2adfeSPhilippe Charnier.Pp 3651bdbdb45SRuslan Ermilov.Bl -column "[:alnum:]" "[:cntrl:]" "[:lower:]" "[:xdigit:]" -compact 3662b0a73baSRuslan Ermilov.It [:alnum:] Ta [:cntrl:] Ta [:lower:] Ta [:space:] 3672b0a73baSRuslan Ermilov.It [:alpha:] Ta [:digit:] Ta [:print:] Ta [:upper:] 3682b0a73baSRuslan Ermilov.It [:blank:] Ta [:graph:] Ta [:punct:] Ta [:xdigit:] 3692b0a73baSRuslan Ermilov.El 37000c2adfeSPhilippe Charnier.Pp 37173ca71feSRuslan ErmilovIf 37273ca71feSRuslan Ermilov.Ql - 37373ca71feSRuslan Ermilovappears as the first or last 37430154ac8SAndrew Moorecharacter of 37500c2adfeSPhilippe Charnier.Em char-class , 37630154ac8SAndrew Moorethen it matches itself. 37730154ac8SAndrew MooreAll other characters in 37800c2adfeSPhilippe Charnier.Em char-class 37930154ac8SAndrew Moorematch themselves. 38000c2adfeSPhilippe Charnier.Pp 38130154ac8SAndrew MoorePatterns in 382056103b6SJoseph Koshy.Em char-class 38330154ac8SAndrew Mooreof the form: 38400c2adfeSPhilippe Charnier.Pp 3852b0a73baSRuslan Ermilov.Bl -item -compact -offset 2n 3862b0a73baSRuslan Ermilov.It 3871586940eSRuslan Ermilov.Op \&. Ns Ar col-elm Ns .\& 3882b0a73baSRuslan Ermilovor, 3892b0a73baSRuslan Ermilov.It 3902b0a73baSRuslan Ermilov.Op = Ns Ar col-elm Ns = 3912b0a73baSRuslan Ermilov.El 39200c2adfeSPhilippe Charnier.Pp 39330154ac8SAndrew Moorewhere 3942b0a73baSRuslan Ermilov.Ar col-elm 39530154ac8SAndrew Mooreis a 39600c2adfeSPhilippe Charnier.Em collating element 397b093b412SGiorgos Keramidasare interpreted according to the current locale settings 39830154ac8SAndrew Moore(not currently supported). 39930154ac8SAndrew MooreSee 40000c2adfeSPhilippe Charnier.Xr regex 3 401b093b412SGiorgos Keramidasand 402b093b412SGiorgos Keramidas.Xr re_format 7 40330154ac8SAndrew Moorefor an explanation of these constructs. 40400c2adfeSPhilippe Charnier.It Op ^char-class 40500c2adfeSPhilippe CharnierMatch any single character, other than newline, not in 40600c2adfeSPhilippe Charnier.Em char-class . 40700c2adfeSPhilippe Charnier.Em Char-class 40830154ac8SAndrew Mooreis defined 40930154ac8SAndrew Mooreas above. 41000c2adfeSPhilippe Charnier.It ^ 41100c2adfeSPhilippe CharnierIf 41200c2adfeSPhilippe Charnier.Em ^ 41300c2adfeSPhilippe Charnieris the first character of a regular expression, then it 41430154ac8SAndrew Mooreanchors the regular expression to the beginning of a line. 41530154ac8SAndrew MooreOtherwise, it matches itself. 41600c2adfeSPhilippe Charnier.It $ 41700c2adfeSPhilippe CharnierIf 41800c2adfeSPhilippe Charnier.Em $ 41900c2adfeSPhilippe Charnieris the last character of a regular expression, it 42030154ac8SAndrew Mooreanchors the regular expression to the end of a line. 42130154ac8SAndrew MooreOtherwise, it matches itself. 42200c2adfeSPhilippe Charnier.It Pf \e < 42300c2adfeSPhilippe CharnierAnchor the single character regular expression or subexpression 42430154ac8SAndrew Mooreimmediately following it to the beginning of a word. 42530154ac8SAndrew Moore(This may not be available) 42600c2adfeSPhilippe Charnier.It Pf \e > 42700c2adfeSPhilippe CharnierAnchor the single character regular expression or subexpression 42830154ac8SAndrew Mooreimmediately following it to the end of a word. 42930154ac8SAndrew Moore(This may not be available) 43000c2adfeSPhilippe Charnier.It Pf \e (re\e) 43100c2adfeSPhilippe CharnierDefine a subexpression 43200c2adfeSPhilippe Charnier.Em re . 43330154ac8SAndrew MooreSubexpressions may be nested. 43400c2adfeSPhilippe CharnierA subsequent backreference of the form 435c2d03ea8SRuslan Ermilov.Pf \e Em n , 43600c2adfeSPhilippe Charnierwhere 43700c2adfeSPhilippe Charnier.Em n 43830154ac8SAndrew Mooreis a number in the range [1,9], expands to the text matched by the 43900c2adfeSPhilippe Charnier.Em n Ns th 44030154ac8SAndrew Mooresubexpression. 44173ca71feSRuslan ErmilovFor example, the regular expression 44273ca71feSRuslan Ermilov.Ql \e(.*\e)\e1 44373ca71feSRuslan Ermilovmatches any string 44430154ac8SAndrew Mooreconsisting of identical adjacent substrings. 44530154ac8SAndrew MooreSubexpressions are ordered relative to 44630154ac8SAndrew Mooretheir left delimiter. 44700c2adfeSPhilippe Charnier.It * 44800c2adfeSPhilippe CharnierMatch the single character regular expression or subexpression 44973ca71feSRuslan Ermilovimmediately preceding it zero or more times. 45073ca71feSRuslan ErmilovIf 45100c2adfeSPhilippe Charnier.Em * 45200c2adfeSPhilippe Charnieris the first 45330154ac8SAndrew Moorecharacter of a regular expression or subexpression, then it matches 45473ca71feSRuslan Ermilovitself. 45573ca71feSRuslan ErmilovThe 45600c2adfeSPhilippe Charnier.Em * 45700c2adfeSPhilippe Charnieroperator sometimes yields unexpected results. 45873ca71feSRuslan ErmilovFor example, the regular expression 45973ca71feSRuslan Ermilov.Ql b* 46073ca71feSRuslan Ermilovmatches the beginning of 46173ca71feSRuslan Ermilovthe string 46273ca71feSRuslan Ermilov.Ql abbb 46373ca71feSRuslan Ermilov(as opposed to the substring 46473ca71feSRuslan Ermilov.Ql bbb ) , 46573ca71feSRuslan Ermilovsince a null match 46630154ac8SAndrew Mooreis the only left-most match. 46700c2adfeSPhilippe Charnier.It \e{n,m\e} or \e{n,\e} or \e{n\e} 46800c2adfeSPhilippe CharnierMatch the single character regular expression or subexpression 46930154ac8SAndrew Mooreimmediately preceding it at least 47000c2adfeSPhilippe Charnier.Em n 47130154ac8SAndrew Mooreand at most 47200c2adfeSPhilippe Charnier.Em m 47330154ac8SAndrew Mooretimes. 47430154ac8SAndrew MooreIf 47500c2adfeSPhilippe Charnier.Em m 47630154ac8SAndrew Mooreis omitted, then it matches at least 47700c2adfeSPhilippe Charnier.Em n 47830154ac8SAndrew Mooretimes. 47930154ac8SAndrew MooreIf the comma is also omitted, then it matches exactly 48000c2adfeSPhilippe Charnier.Em n 48130154ac8SAndrew Mooretimes. 48200c2adfeSPhilippe Charnier.El 48300c2adfeSPhilippe Charnier.Pp 48430154ac8SAndrew MooreAdditional regular expression operators may be defined depending on the 48530154ac8SAndrew Mooreparticular 48600c2adfeSPhilippe Charnier.Xr regex 3 48730154ac8SAndrew Mooreimplementation. 48800c2adfeSPhilippe Charnier.Sh COMMANDS 48930154ac8SAndrew MooreAll 49000c2adfeSPhilippe Charnier.Nm 491e3d79adaSJohn-Mark Gurneycommands are single characters, though some require additional parameters. 49230154ac8SAndrew MooreIf a command's parameters extend over several lines, then 49330154ac8SAndrew Mooreeach line except for the last 49430154ac8SAndrew Mooremust be terminated with a backslash (\\). 49512e720d7SRuslan Ermilov.Pp 49630154ac8SAndrew MooreIn general, at most one command is allowed per line. 49730154ac8SAndrew MooreHowever, most commands accept a print suffix, which is any of 49800c2adfeSPhilippe Charnier.Em p 49930154ac8SAndrew Moore(print), 50000c2adfeSPhilippe Charnier.Em l 50130154ac8SAndrew Moore(list), 50230154ac8SAndrew Mooreor 50300c2adfeSPhilippe Charnier.Em n 50430154ac8SAndrew Moore(enumerate), 50530154ac8SAndrew Mooreto print the last line affected by the command. 50612e720d7SRuslan Ermilov.Pp 50730154ac8SAndrew MooreAn interrupt (typically ^C) has the effect of aborting the current command 50830154ac8SAndrew Mooreand returning the editor to command mode. 50912e720d7SRuslan Ermilov.Pp 510e004acc8SPhilippe CharnierThe 511e004acc8SPhilippe Charnier.Nm 512e004acc8SPhilippe Charnierutility 51373ca71feSRuslan Ermilovrecognizes the following commands. 51473ca71feSRuslan ErmilovThe commands are shown together with 51530154ac8SAndrew Moorethe default address or address range supplied if none is 51630154ac8SAndrew Moorespecified (in parenthesis). 51700c2adfeSPhilippe Charnier.Bl -tag -width indent 51800c2adfeSPhilippe Charnier.It (.)a 51900c2adfeSPhilippe CharnierAppend text to the buffer after the addressed line. 52030154ac8SAndrew MooreText is entered in input mode. 52130154ac8SAndrew MooreThe current address is set to last line entered. 52200c2adfeSPhilippe Charnier.It (.,.)c 52373ca71feSRuslan ErmilovChange lines in the buffer. 52473ca71feSRuslan ErmilovThe addressed lines are deleted 52530154ac8SAndrew Moorefrom the buffer, and text is appended in their place. 52630154ac8SAndrew MooreText is entered in input mode. 52730154ac8SAndrew MooreThe current address is set to last line entered. 52800c2adfeSPhilippe Charnier.It (.,.)d 52900c2adfeSPhilippe CharnierDelete the addressed lines from the buffer. 53030154ac8SAndrew MooreIf there is a line after the deleted range, then the current address is set 531bef84d6bSSheldon Hearnto this line. 532bef84d6bSSheldon HearnOtherwise the current address is set to the line 53330154ac8SAndrew Moorebefore the deleted range. 53400c2adfeSPhilippe Charnier.It e Ar file 53500c2adfeSPhilippe CharnierEdit 53600c2adfeSPhilippe Charnier.Ar file , 53730154ac8SAndrew Mooreand sets the default filename. 53830154ac8SAndrew MooreIf 53900c2adfeSPhilippe Charnier.Ar file 54030154ac8SAndrew Mooreis not specified, then the default filename is used. 54130154ac8SAndrew MooreAny lines in the buffer are deleted before 54230154ac8SAndrew Moorethe new file is read. 54330154ac8SAndrew MooreThe current address is set to the last line read. 54400c2adfeSPhilippe Charnier.It e Ar !command 54500c2adfeSPhilippe CharnierEdit the standard output of 54600c2adfeSPhilippe Charnier.Ar !command , 54795e6217eSAndrew Moore(see 54800c2adfeSPhilippe Charnier.Ar !command 54995e6217eSAndrew Moorebelow). 55030154ac8SAndrew MooreThe default filename is unchanged. 55130154ac8SAndrew MooreAny lines in the buffer are deleted before the output of 55200c2adfeSPhilippe Charnier.Ar command 55330154ac8SAndrew Mooreis read. 55430154ac8SAndrew MooreThe current address is set to the last line read. 55500c2adfeSPhilippe Charnier.It E Ar file 55600c2adfeSPhilippe CharnierEdit 55700c2adfeSPhilippe Charnier.Ar file 55830154ac8SAndrew Mooreunconditionally. 55930154ac8SAndrew MooreThis is similar to the 56000c2adfeSPhilippe Charnier.Em e 56130154ac8SAndrew Moorecommand, 56230154ac8SAndrew Mooreexcept that unwritten changes are discarded without warning. 56330154ac8SAndrew MooreThe current address is set to the last line read. 56400c2adfeSPhilippe Charnier.It f Ar file 56500c2adfeSPhilippe CharnierSet the default filename to 56600c2adfeSPhilippe Charnier.Ar file . 56730154ac8SAndrew MooreIf 56800c2adfeSPhilippe Charnier.Ar file 56930154ac8SAndrew Mooreis not specified, then the default unescaped filename is printed. 57000c2adfeSPhilippe Charnier.It (1,$)g/re/command-list 57100c2adfeSPhilippe CharnierApply 57200c2adfeSPhilippe Charnier.Ar command-list 57330154ac8SAndrew Mooreto each of the addressed lines matching a regular expression 57400c2adfeSPhilippe Charnier.Ar re . 57530154ac8SAndrew MooreThe current address is set to the 57630154ac8SAndrew Mooreline currently matched before 57700c2adfeSPhilippe Charnier.Ar command-list 57830154ac8SAndrew Mooreis executed. 57930154ac8SAndrew MooreAt the end of the 58000c2adfeSPhilippe Charnier.Em g 58130154ac8SAndrew Moorecommand, the current address is set to the last line affected by 58200c2adfeSPhilippe Charnier.Ar command-list . 58300c2adfeSPhilippe Charnier.Pp 58430154ac8SAndrew MooreEach command in 58500c2adfeSPhilippe Charnier.Ar command-list 58630154ac8SAndrew Mooremust be on a separate line, 58730154ac8SAndrew Mooreand every line except for the last must be terminated by a backslash 58830154ac8SAndrew Moore(\\). 58930154ac8SAndrew MooreAny commands are allowed, except for 59000c2adfeSPhilippe Charnier.Em g , 59100c2adfeSPhilippe Charnier.Em G , 59200c2adfeSPhilippe Charnier.Em v , 59330154ac8SAndrew Mooreand 59400c2adfeSPhilippe Charnier.Em V . 59530154ac8SAndrew MooreA newline alone in 59600c2adfeSPhilippe Charnier.Ar command-list 59730154ac8SAndrew Mooreis equivalent to a 59800c2adfeSPhilippe Charnier.Em p 59930154ac8SAndrew Moorecommand. 60000c2adfeSPhilippe Charnier.It (1,$)G/re/ 60100c2adfeSPhilippe CharnierInteractively edit the addressed lines matching a regular expression 60200c2adfeSPhilippe Charnier.Ar re . 60330154ac8SAndrew MooreFor each matching line, 60430154ac8SAndrew Moorethe line is printed, 60530154ac8SAndrew Moorethe current address is set, 60630154ac8SAndrew Mooreand the user is prompted to enter a 60700c2adfeSPhilippe Charnier.Ar command-list . 60830154ac8SAndrew MooreAt the end of the 60900c2adfeSPhilippe Charnier.Em G 61030154ac8SAndrew Moorecommand, the current address 61130154ac8SAndrew Mooreis set to the last line affected by (the last) 61200c2adfeSPhilippe Charnier.Ar command-list . 61300c2adfeSPhilippe Charnier.Pp 61430154ac8SAndrew MooreThe format of 61500c2adfeSPhilippe Charnier.Ar command-list 61630154ac8SAndrew Mooreis the same as that of the 61700c2adfeSPhilippe Charnier.Em g 61873ca71feSRuslan Ermilovcommand. 61973ca71feSRuslan ErmilovA newline alone acts as a null command list. 62073ca71feSRuslan ErmilovA single 62173ca71feSRuslan Ermilov.Ql & 62273ca71feSRuslan Ermilovrepeats the last non-null command list. 62300c2adfeSPhilippe Charnier.It H 62400c2adfeSPhilippe CharnierToggle the printing of error explanations. 62530154ac8SAndrew MooreBy default, explanations are not printed. 62630154ac8SAndrew MooreIt is recommended that ed scripts begin with this command to 62730154ac8SAndrew Mooreaid in debugging. 62800c2adfeSPhilippe Charnier.It h 62900c2adfeSPhilippe CharnierPrint an explanation of the last error. 63000c2adfeSPhilippe Charnier.It (.)i 63100c2adfeSPhilippe CharnierInsert text in the buffer before the current line. 63230154ac8SAndrew MooreText is entered in input mode. 63330154ac8SAndrew MooreThe current address is set to the last line entered. 63400c2adfeSPhilippe Charnier.It (.,.+1)j 63573ca71feSRuslan ErmilovJoin the addressed lines. 63673ca71feSRuslan ErmilovThe addressed lines are 63730154ac8SAndrew Mooredeleted from the buffer and replaced by a single 63830154ac8SAndrew Mooreline containing their joined text. 63930154ac8SAndrew MooreThe current address is set to the resultant line. 64000c2adfeSPhilippe Charnier.It (.)klc 64100c2adfeSPhilippe CharnierMark a line with a lower case letter 64200c2adfeSPhilippe Charnier.Em lc . 64330154ac8SAndrew MooreThe line can then be addressed as 64400c2adfeSPhilippe Charnier.Em 'lc 64530154ac8SAndrew Moore(i.e., a single quote followed by 64694ba280cSRuslan Ermilov.Em lc ) 64773ca71feSRuslan Ermilovin subsequent commands. 64873ca71feSRuslan ErmilovThe mark is not cleared until the line is 64930154ac8SAndrew Mooredeleted or otherwise modified. 65000c2adfeSPhilippe Charnier.It (.,.)l 65100c2adfeSPhilippe CharnierPrint the addressed lines unambiguously. 652f68fbfedSRebecca CranIf a single line fills more than one screen (as might be the case 65373ca71feSRuslan Ermilovwhen viewing a binary file, for instance), a 65473ca71feSRuslan Ermilov.Dq Li --More-- 65595e6217eSAndrew Mooreprompt is printed on the last line. 656e004acc8SPhilippe CharnierThe 657e004acc8SPhilippe Charnier.Nm 658e004acc8SPhilippe Charnierutility waits until the RETURN key is pressed 65995e6217eSAndrew Moorebefore displaying the next screen. 66030154ac8SAndrew MooreThe current address is set to the last line 66130154ac8SAndrew Mooreprinted. 66200c2adfeSPhilippe Charnier.It (.,.)m(.) 66373ca71feSRuslan ErmilovMove lines in the buffer. 66473ca71feSRuslan ErmilovThe addressed lines are moved to after the 66530154ac8SAndrew Mooreright-hand destination address, which may be the address 66600c2adfeSPhilippe Charnier.Em 0 66730154ac8SAndrew Moore(zero). 66830154ac8SAndrew MooreThe current address is set to the 66930154ac8SAndrew Moorelast line moved. 67000c2adfeSPhilippe Charnier.It (.,.)n 67100c2adfeSPhilippe CharnierPrint the addressed lines along with 67273ca71feSRuslan Ermilovtheir line numbers. 67373ca71feSRuslan ErmilovThe current address is set to the last line 67430154ac8SAndrew Mooreprinted. 67500c2adfeSPhilippe Charnier.It (.,.)p 676bef84d6bSSheldon HearnPrint the addressed lines. 677bef84d6bSSheldon HearnThe current address is set to the last line 67830154ac8SAndrew Mooreprinted. 67900c2adfeSPhilippe Charnier.It P 68000c2adfeSPhilippe CharnierToggle the command prompt on and off. 68130154ac8SAndrew MooreUnless a prompt was specified by with command-line option 68200c2adfeSPhilippe Charnier.Fl p Ar string , 68300c2adfeSPhilippe Charnierthe command prompt is by default turned off. 68400c2adfeSPhilippe Charnier.It q 68500c2adfeSPhilippe CharnierQuit 686be8b1497SRuslan Ermilov.Nm . 68700c2adfeSPhilippe Charnier.It Q 68800c2adfeSPhilippe CharnierQuit 68900c2adfeSPhilippe Charnier.Nm 69000c2adfeSPhilippe Charnierunconditionally. 69130154ac8SAndrew MooreThis is similar to the 69200c2adfeSPhilippe Charnier.Em q 69330154ac8SAndrew Moorecommand, 69430154ac8SAndrew Mooreexcept that unwritten changes are discarded without warning. 69500c2adfeSPhilippe Charnier.It ($)r Ar file 69600c2adfeSPhilippe CharnierRead 69700c2adfeSPhilippe Charnier.Ar file 69873ca71feSRuslan Ermilovto after the addressed line. 69973ca71feSRuslan ErmilovIf 70000c2adfeSPhilippe Charnier.Ar file 70130154ac8SAndrew Mooreis not specified, then the default 70273ca71feSRuslan Ermilovfilename is used. 70373ca71feSRuslan ErmilovIf there was no default filename prior to the command, 70430154ac8SAndrew Moorethen the default filename is set to 70500c2adfeSPhilippe Charnier.Ar file . 70630154ac8SAndrew MooreOtherwise, the default filename is unchanged. 70730154ac8SAndrew MooreThe current address is set to the last line read. 70800c2adfeSPhilippe Charnier.It ($)r Ar !command 70900c2adfeSPhilippe CharnierRead 71030154ac8SAndrew Mooreto after the addressed line 71130154ac8SAndrew Moorethe standard output of 71200c2adfeSPhilippe Charnier.Ar !command , 71395e6217eSAndrew Moore(see the 71400c2adfeSPhilippe Charnier.Ar !command 71595e6217eSAndrew Moorebelow). 71630154ac8SAndrew MooreThe default filename is unchanged. 71730154ac8SAndrew MooreThe current address is set to the last line read. 71800c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/ 71900c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/g 72000c2adfeSPhilippe Charnier.It (.,.)s/re/replacement/n 72100c2adfeSPhilippe CharnierReplace text in the addressed lines 72230154ac8SAndrew Moorematching a regular expression 72300c2adfeSPhilippe Charnier.Ar re 72430154ac8SAndrew Moorewith 72500c2adfeSPhilippe Charnier.Ar replacement . 72630154ac8SAndrew MooreBy default, only the first match in each line is replaced. 72795e6217eSAndrew MooreIf the 72800c2adfeSPhilippe Charnier.Em g 72995e6217eSAndrew Moore(global) suffix is given, then every match to be replaced. 73030154ac8SAndrew MooreThe 73100c2adfeSPhilippe Charnier.Em n 73230154ac8SAndrew Mooresuffix, where 73300c2adfeSPhilippe Charnier.Em n 73460fd953fSJordan K. Hubbardis a positive number, causes only the 73500c2adfeSPhilippe Charnier.Em n Ns th 73630154ac8SAndrew Moorematch to be replaced. 73730154ac8SAndrew MooreIt is an error if no substitutions are performed on any of the addressed 73830154ac8SAndrew Moorelines. 73930154ac8SAndrew MooreThe current address is set the last line affected. 74000c2adfeSPhilippe Charnier.Pp 7411517e564SBaptiste Daroussin.Ar \&Re 74230154ac8SAndrew Mooreand 74300c2adfeSPhilippe Charnier.Ar replacement 74495e6217eSAndrew Mooremay be delimited by any character other than space and newline 74595e6217eSAndrew Moore(see the 74600c2adfeSPhilippe Charnier.Em s 74795e6217eSAndrew Moorecommand below). 74830154ac8SAndrew MooreIf one or two of the last delimiters is omitted, then the last line 74930154ac8SAndrew Mooreaffected is printed as though the print suffix 75000c2adfeSPhilippe Charnier.Em p 75130154ac8SAndrew Moorewere specified. 75200c2adfeSPhilippe Charnier.Pp 75373ca71feSRuslan ErmilovAn unescaped 75473ca71feSRuslan Ermilov.Ql & 75573ca71feSRuslan Ermilovin 75600c2adfeSPhilippe Charnier.Ar replacement 75730154ac8SAndrew Mooreis replaced by the currently matched text. 75830154ac8SAndrew MooreThe character sequence 75900c2adfeSPhilippe Charnier.Em \em , 76030154ac8SAndrew Moorewhere 76100c2adfeSPhilippe Charnier.Em m 76230154ac8SAndrew Mooreis a number in the range [1,9], is replaced by the 76300c2adfeSPhilippe Charnier.Em m th 76430154ac8SAndrew Moorebackreference expression of the matched text. 76530154ac8SAndrew MooreIf 76600c2adfeSPhilippe Charnier.Ar replacement 76773ca71feSRuslan Ermilovconsists of a single 76873ca71feSRuslan Ermilov.Ql % , 76973ca71feSRuslan Ermilovthen 77000c2adfeSPhilippe Charnier.Ar replacement 77130154ac8SAndrew Moorefrom the last substitution is used. 77230154ac8SAndrew MooreNewlines may be embedded in 77300c2adfeSPhilippe Charnier.Ar replacement 77430154ac8SAndrew Mooreif they are escaped with a backslash (\\). 77500c2adfeSPhilippe Charnier.It (.,.)s 77600c2adfeSPhilippe CharnierRepeat the last substitution. 77730154ac8SAndrew MooreThis form of the 77800c2adfeSPhilippe Charnier.Em s 77995e6217eSAndrew Moorecommand accepts a count suffix 78000c2adfeSPhilippe Charnier.Em n , 78195e6217eSAndrew Mooreor any combination of the characters 78200c2adfeSPhilippe Charnier.Em r , 78300c2adfeSPhilippe Charnier.Em g , 78430154ac8SAndrew Mooreand 78500c2adfeSPhilippe Charnier.Em p . 78695e6217eSAndrew MooreIf a count suffix 78700c2adfeSPhilippe Charnier.Em n 78895e6217eSAndrew Mooreis given, then only the 78900c2adfeSPhilippe Charnier.Em n Ns th 79095e6217eSAndrew Moorematch is replaced. 79130154ac8SAndrew MooreThe 79200c2adfeSPhilippe Charnier.Em r 79330154ac8SAndrew Mooresuffix causes 79430154ac8SAndrew Moorethe regular expression of the last search to be used instead of the 79530154ac8SAndrew Moorethat of the last substitution. 79630154ac8SAndrew MooreThe 79700c2adfeSPhilippe Charnier.Em g 79830154ac8SAndrew Mooresuffix toggles the global suffix of the last substitution. 79930154ac8SAndrew MooreThe 80000c2adfeSPhilippe Charnier.Em p 80130154ac8SAndrew Mooresuffix toggles the print suffix of the last substitution 80230154ac8SAndrew MooreThe current address is set to the last line affected. 80300c2adfeSPhilippe Charnier.It (.,.)t(.) 80400c2adfeSPhilippe CharnierCopy (i.e., transfer) the addressed lines to after the right-hand 80530154ac8SAndrew Mooredestination address, which may be the address 80600c2adfeSPhilippe Charnier.Em 0 80730154ac8SAndrew Moore(zero). 80830154ac8SAndrew MooreThe current address is set to the last line 80930154ac8SAndrew Moorecopied. 81000c2adfeSPhilippe Charnier.It u 81100c2adfeSPhilippe CharnierUndo the last command and restores the current address 81230154ac8SAndrew Mooreto what it was before the command. 81330154ac8SAndrew MooreThe global commands 81400c2adfeSPhilippe Charnier.Em g , 81500c2adfeSPhilippe Charnier.Em G , 81600c2adfeSPhilippe Charnier.Em v , 81730154ac8SAndrew Mooreand 81800c2adfeSPhilippe Charnier.Em V . 81930154ac8SAndrew Mooreare treated as a single command by undo. 82000c2adfeSPhilippe Charnier.Em u 82130154ac8SAndrew Mooreis its own inverse. 82200c2adfeSPhilippe Charnier.It (1,$)v/re/command-list 82300c2adfeSPhilippe CharnierApply 82400c2adfeSPhilippe Charnier.Ar command-list 82530154ac8SAndrew Mooreto each of 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,$)V/re/ 83100c2adfeSPhilippe CharnierInteractively edit the addressed lines not matching a regular expression 83200c2adfeSPhilippe Charnier.Ar re . 83330154ac8SAndrew MooreThis is similar to the 83400c2adfeSPhilippe Charnier.Em G 83530154ac8SAndrew Moorecommand. 83600c2adfeSPhilippe Charnier.It (1,$)w Ar file 83700c2adfeSPhilippe CharnierWrite the addressed lines to 83800c2adfeSPhilippe Charnier.Ar file . 83930154ac8SAndrew MooreAny previous contents of 84000c2adfeSPhilippe Charnier.Ar file 84130154ac8SAndrew Mooreis lost without warning. 84230154ac8SAndrew MooreIf there is no default filename, then the default filename is set to 84300c2adfeSPhilippe Charnier.Ar file , 84473ca71feSRuslan Ermilovotherwise it is unchanged. 84573ca71feSRuslan ErmilovIf no filename is specified, then the default 84630154ac8SAndrew Moorefilename is used. 84730154ac8SAndrew MooreThe current address is unchanged. 84800c2adfeSPhilippe Charnier.It (1,$)wq Ar file 84900c2adfeSPhilippe CharnierWrite the addressed lines to 85000c2adfeSPhilippe Charnier.Ar file , 85130154ac8SAndrew Mooreand then executes a 85200c2adfeSPhilippe Charnier.Em q 85330154ac8SAndrew Moorecommand. 85400c2adfeSPhilippe Charnier.It (1,$)w Ar !command 85500c2adfeSPhilippe CharnierWrite the addressed lines to the standard input of 85600c2adfeSPhilippe Charnier.Ar !command , 85795e6217eSAndrew Moore(see the 85800c2adfeSPhilippe Charnier.Em !command 85995e6217eSAndrew Moorebelow). 86030154ac8SAndrew MooreThe default filename and current address are unchanged. 86100c2adfeSPhilippe Charnier.It (1,$)W Ar file 86200c2adfeSPhilippe CharnierAppend the addressed lines to the end of 86300c2adfeSPhilippe Charnier.Ar file . 86430154ac8SAndrew MooreThis is similar to the 86500c2adfeSPhilippe Charnier.Em w 86630154ac8SAndrew Moorecommand, expect that the previous contents of file is not clobbered. 86730154ac8SAndrew MooreThe current address is unchanged. 86800c2adfeSPhilippe Charnier.It x 86900c2adfeSPhilippe CharnierPrompt for an encryption key which is used in subsequent reads and 87073ca71feSRuslan Ermilovwrites. 87173ca71feSRuslan ErmilovIf a newline alone is entered as the key, then encryption is 87273ca71feSRuslan Ermilovturned off. 87373ca71feSRuslan ErmilovOtherwise, echoing is disabled while a key is read. 87400c2adfeSPhilippe CharnierEncryption/decryption is done using the 87500c2adfeSPhilippe Charnier.Xr bdes 1 87600c2adfeSPhilippe Charnieralgorithm. 87700c2adfeSPhilippe Charnier.It Pf (.+1)z n 87800c2adfeSPhilippe CharnierScroll 87900c2adfeSPhilippe Charnier.Ar n 88073ca71feSRuslan Ermilovlines at a time starting at addressed line. 88173ca71feSRuslan ErmilovIf 88200c2adfeSPhilippe Charnier.Ar n 88330154ac8SAndrew Mooreis not specified, then the current window size is used. 88430154ac8SAndrew MooreThe current address is set to the last line printed. 88500c2adfeSPhilippe Charnier.It !command 88600c2adfeSPhilippe CharnierExecute 88700c2adfeSPhilippe Charnier.Ar command 88830154ac8SAndrew Moorevia 88900c2adfeSPhilippe Charnier.Xr sh 1 . 89030154ac8SAndrew MooreIf the first character of 89100c2adfeSPhilippe Charnier.Ar command 89273ca71feSRuslan Ermilovis 89373ca71feSRuslan Ermilov.Ql \&! , 89473ca71feSRuslan Ermilovthen it is replaced by text of the 89530154ac8SAndrew Mooreprevious 89600c2adfeSPhilippe Charnier.Ar !command . 897e004acc8SPhilippe CharnierThe 898e004acc8SPhilippe Charnier.Nm 899e004acc8SPhilippe Charnierutility does not process 90000c2adfeSPhilippe Charnier.Ar command 90130154ac8SAndrew Moorefor backslash (\\) escapes. 90230154ac8SAndrew MooreHowever, an unescaped 90300c2adfeSPhilippe Charnier.Em % 90430154ac8SAndrew Mooreis replaced by the default filename. 90573ca71feSRuslan ErmilovWhen the shell returns from execution, a 90673ca71feSRuslan Ermilov.Ql \&! 90730154ac8SAndrew Mooreis printed to the standard output. 90830154ac8SAndrew MooreThe current line is unchanged. 90900c2adfeSPhilippe Charnier.It ($)= 91000c2adfeSPhilippe CharnierPrint the line number of the addressed line. 91100c2adfeSPhilippe Charnier.It (.+1)newline 91200c2adfeSPhilippe CharnierPrint the addressed line, and sets the current address to 91330154ac8SAndrew Moorethat line. 91400c2adfeSPhilippe Charnier.El 91500c2adfeSPhilippe Charnier.Sh FILES 91600c2adfeSPhilippe Charnier.Bl -tag -width /tmp/ed.* -compact 9172710751bSJoel Dahl.It Pa /tmp/ed.* 91800c2adfeSPhilippe Charnierbuffer file 9192710751bSJoel Dahl.It Pa ed.hup 92000c2adfeSPhilippe Charnierthe file to which 92100c2adfeSPhilippe Charnier.Nm 92200c2adfeSPhilippe Charnierattempts to write the buffer if the terminal hangs up 92300c2adfeSPhilippe Charnier.El 92400c2adfeSPhilippe Charnier.Sh DIAGNOSTICS 92530154ac8SAndrew MooreWhen an error occurs, 92600c2adfeSPhilippe Charnier.Nm 92773ca71feSRuslan Ermilovprints a 92873ca71feSRuslan Ermilov.Ql \&? 92973ca71feSRuslan Ermilovand either returns to command mode 93030154ac8SAndrew Mooreor exits if its input is from a script. 93130154ac8SAndrew MooreAn explanation of the last error can be 93230154ac8SAndrew Mooreprinted with the 93300c2adfeSPhilippe Charnier.Em h 93430154ac8SAndrew Moore(help) command. 93512e720d7SRuslan Ermilov.Pp 93630154ac8SAndrew MooreSince the 93700c2adfeSPhilippe Charnier.Em g 93830154ac8SAndrew Moore(global) command masks any errors from failed searches and substitutions, 93930154ac8SAndrew Mooreit can be used to perform conditional operations in scripts; e.g., 94000c2adfeSPhilippe Charnier.Pp 94100c2adfeSPhilippe Charnier.Sm off 94200c2adfeSPhilippe Charnier.Cm g No / Em old Xo 94300c2adfeSPhilippe Charnier.No / Cm s 94400c2adfeSPhilippe Charnier.No // Em new 94500c2adfeSPhilippe Charnier.No / 94600c2adfeSPhilippe Charnier.Xc 94700c2adfeSPhilippe Charnier.Sm on 94800c2adfeSPhilippe Charnier.Pp 94930154ac8SAndrew Moorereplaces any occurrences of 95000c2adfeSPhilippe Charnier.Em old 95130154ac8SAndrew Moorewith 95200c2adfeSPhilippe Charnier.Em new . 95310ca1c6cSAndrew MooreIf the 95400c2adfeSPhilippe Charnier.Em u 95510ca1c6cSAndrew Moore(undo) command occurs in a global command list, then 95610ca1c6cSAndrew Moorethe command list is executed only once. 95712e720d7SRuslan Ermilov.Pp 95830154ac8SAndrew MooreIf diagnostics are not disabled, attempting to quit 95900c2adfeSPhilippe Charnier.Nm 96030154ac8SAndrew Mooreor edit another file before writing a modified buffer 96130154ac8SAndrew Mooreresults in an error. 96230154ac8SAndrew MooreIf the command is entered a second time, it succeeds, 96330154ac8SAndrew Moorebut any changes to the buffer are lost. 9646fca4c7cSRuslan Ermilov.Sh SEE ALSO 9656fca4c7cSRuslan Ermilov.Xr bdes 1 , 9666fca4c7cSRuslan Ermilov.Xr sed 1 , 9676fca4c7cSRuslan Ermilov.Xr sh 1 , 9686fca4c7cSRuslan Ermilov.Xr vi 1 , 9696fca4c7cSRuslan Ermilov.Xr regex 3 9706fca4c7cSRuslan Ermilov.Pp 9716fca4c7cSRuslan ErmilovUSD:12-13 9726fca4c7cSRuslan Ermilov.Rs 9736fca4c7cSRuslan Ermilov.%A B. W. Kernighan 9746fca4c7cSRuslan Ermilov.%A P. J. Plauger 9756fca4c7cSRuslan Ermilov.%B Software Tools in Pascal 9766fca4c7cSRuslan Ermilov.%O Addison-Wesley 9776fca4c7cSRuslan Ermilov.%D 1981 9786fca4c7cSRuslan Ermilov.Re 9796fca4c7cSRuslan Ermilov.Sh LIMITATIONS 9806fca4c7cSRuslan ErmilovThe 9816fca4c7cSRuslan Ermilov.Nm 9826fca4c7cSRuslan Ermilovutility processes 9836fca4c7cSRuslan Ermilov.Ar file 9846fca4c7cSRuslan Ermilovarguments for backslash escapes, i.e., in a filename, 9856fca4c7cSRuslan Ermilovany characters preceded by a backslash (\\) are 9866fca4c7cSRuslan Ermilovinterpreted literally. 9876fca4c7cSRuslan Ermilov.Pp 9886fca4c7cSRuslan ErmilovIf a text (non-binary) file is not terminated by a newline character, 9896fca4c7cSRuslan Ermilovthen 9906fca4c7cSRuslan Ermilov.Nm 9916fca4c7cSRuslan Ermilovappends one on reading/writing it. 9926fca4c7cSRuslan ErmilovIn the case of a binary file, 9936fca4c7cSRuslan Ermilov.Nm 9946fca4c7cSRuslan Ermilovdoes not append a newline on reading/writing. 9956fca4c7cSRuslan Ermilov.Pp 9966fca4c7cSRuslan Ermilovper line overhead: 4 ints 99700c2adfeSPhilippe Charnier.Sh HISTORY 9989076772fSDima DorfmanAn 99900c2adfeSPhilippe Charnier.Nm 1000b8923d4cSWolfram Schneidercommand appeared in 1001bc799c51SSevan Janiyan.At v1 . 1002128dc4a2STim J. Robbins.Sh BUGS 1003128dc4a2STim J. RobbinsThe 1004128dc4a2STim J. Robbins.Nm 1005128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 1006