22 utility is a line-oriented text editor.
23 It is used to create, display, modify and otherwise manipulate text
29 mode, in which the only difference is that the editor restricts the
30 use of filenames which start with
32 (interpreted as shell commands by
36 Note that editing outside of the current directory is only prohibited
37 if the user does not have write access to the current directory.
38 If a user has write access to the current directory, then symbolic
39 links can be created in the current directory, in which case
41 will not stop the user from editing the file that the symbolic link
46 argument, then a copy of
48 is read into the editor's buffer.
49 Changes are made to this copy and not directly to
54 any changes not explicitly saved with a
58 Editing is done in two distinct modes:
65 In this mode commands are read from the standard input and
66 executed to manipulate the contents of the editor buffer.
67 A typical command might look like:
76 which replaces all occurrences of the string
81 When an input command, such as
90 This is the primary means
91 of adding text to a file.
92 In this mode, no commands are available;
93 instead, the standard input is written
94 directly to the editor buffer.
95 Lines consist of text up to and
99 Input mode is terminated by
100 entering a single period
106 commands operate on whole lines or ranges of lines; e.g.,
109 command deletes lines; the
111 command moves lines, and so on.
112 It is possible to modify only a portion of a line by means of replacement,
113 as in the example above.
114 However even here, the
116 command is applied to whole lines at a time.
120 commands consist of zero or more line addresses, followed by a single
121 character command and possibly additional parameters; i.e.,
122 commands have the structure:
126 .Op Ar address Op , Ar address
127 .Ar command Op Ar parameters
131 The address(es) indicate the line or range of lines to be affected by the
133 If fewer addresses are given than the command accepts, then
134 default addresses are supplied.
136 The following options are available:
137 .Bl -tag -width indent
139 Suppress diagnostics.
140 This should be used if
142 standard input is from a script.
144 Specify a command prompt.
145 This may be toggled on and off with the
149 Specify the name of a file to read.
153 bang (!), then it is interpreted as a shell command.
156 the standard output of
160 To read a file whose name begins with a bang, prefix the
161 name with a backslash (\\).
162 The default filename is set to
164 only if it is not prefixed with a bang.
167 An address represents the number of a line in the buffer.
173 typically supplied to commands as the default address when none is specified.
174 When a file is first read, the current address is set to the last line
176 In general, the current address is set to the last line
177 affected by a command.
180 constructed from one of the bases in the list below, optionally followed
182 The offset may include any combination
183 of digits, operators (i.e.,
189 Addresses are read from left to right, and their values are computed
190 relative to the current address.
192 One exception to the rule that addresses represent line numbers is the
196 This means "before the first line,"
197 and is legal wherever it makes sense.
199 An address range is two addresses separated either by a comma or
201 The value of the first address in a range cannot exceed the
203 If only one address is given in a range, then
204 the second address is set to the given address.
207 of addresses is given where
209 then the corresponding range is determined by the last two addresses in
212 If only one address is expected, then the last address is used.
214 Each address in a comma-delimited range is interpreted relative to the
216 In a semi-colon-delimited range, the first address is
217 used to set the current address, and the second address is interpreted
218 relative to the first.
220 The following address symbols are recognized:
221 .Bl -tag -width indent
223 The current line (address) in the buffer.
225 The last line in the buffer.
232 is a number in the range
236 This is equivalent to
238 and may be repeated with cumulative effect.
244 is a non-negative number.
247 This is equivalent to
249 and may be repeated with cumulative effect.
255 is a non-negative number.
257 The first through last lines in the buffer.
258 This is equivalent to
262 The current through last lines in the buffer.
263 This is equivalent to
267 The next line containing the regular expression
269 The search wraps to the beginning of the buffer and continues down to the
270 current line, if necessary.
271 // repeats the last search.
274 previous line containing the regular expression
276 The search wraps to the end of the buffer and continues up to the
277 current line, if necessary.
278 ?? repeats the last search.
281 line previously marked by a
283 (mark) command, where
285 is a lower case letter.
287 .Sh REGULAR EXPRESSIONS
288 Regular expressions are patterns used in selecting text.
289 For example, the command:
292 .Cm g No / Em string Xo
297 prints all lines containing
299 Regular expressions are also
302 command for selecting old text to be replaced with new.
304 In addition to a specifying string literals, regular expressions can
307 Strings thus represented are said to be matched
308 by the corresponding regular expression.
309 If it is possible for a regular expression
310 to match several strings in a line, then the left-most longest match is
313 The following symbols are used in constructing regular expressions:
314 .Bl -tag -width indent
318 not listed below, including
328 Any backslash-escaped character
340 Match any single character.
342 Match any single character in
348 it must be the first character.
349 A range of characters may be specified by separating the end characters
354 specifies the lower case characters.
355 The following literal expressions can also be used in
357 to specify sets of characters:
359 .Bl -column "[:alnum:]" "[:cntrl:]" "[:lower:]" "[:xdigit:]" -compact
360 .It [:alnum:] Ta [:cntrl:] Ta [:lower:] Ta [:space:]
361 .It [:alpha:] Ta [:digit:] Ta [:print:] Ta [:upper:]
362 .It [:blank:] Ta [:graph:] Ta [:punct:] Ta [:xdigit:]
367 appears as the first or last
370 then it matches itself.
371 All other characters in
379 .Bl -item -compact -offset 2n
381 .Op \&. Ns Ar col-elm Ns .\&
384 .Op = Ns Ar col-elm Ns =
390 .Em collating element
391 are interpreted according to the current locale settings
392 (not currently supported).
397 for an explanation of these constructs.
399 Match any single character, other than newline, not in
407 is the first character of a regular expression, then it
408 anchors the regular expression to the beginning of a line.
409 Otherwise, it matches itself.
413 is the last character of a regular expression, it
414 anchors the regular expression to the end of a line.
415 Otherwise, it matches itself.
417 Anchor the single character regular expression or subexpression
418 immediately following it to the beginning of a word.
419 (This may not be available)
421 Anchor the single character regular expression or subexpression
422 immediately following it to the end of a word.
423 (This may not be available)
425 Define a subexpression
427 Subexpressions may be nested.
428 A subsequent backreference of the form
432 is a number in the range [1,9], expands to the text matched by the
435 For example, the regular expression
438 consisting of identical adjacent substrings.
439 Subexpressions are ordered relative to
440 their left delimiter.
442 Match the single character regular expression or subexpression
443 immediately preceding it zero or more times.
447 character of a regular expression or subexpression, then it matches
451 operator sometimes yields unexpected results.
452 For example, the regular expression
454 matches the beginning of
457 (as opposed to the substring
460 is the only left-most match.
461 .It \e{n,m\e} or \e{n,\e} or \e{n\e}
462 Match the single character regular expression or subexpression
463 immediately preceding it at least
470 is omitted, then it matches at least
473 If the comma is also omitted, then it matches exactly
478 Additional regular expression operators may be defined depending on the
485 commands are single characters, though some require additional parameters.
486 If a command's parameters extend over several lines, then
487 each line except for the last
488 must be terminated with a backslash (\\).
490 In general, at most one command is allowed per line.
491 However, most commands accept a print suffix, which is any of
499 to print the last line affected by the command.
501 An interrupt (typically ^C) has the effect of aborting the current command
502 and returning the editor to command mode.
507 recognizes the following commands.
508 The commands are shown together with
509 the default address or address range supplied if none is
510 specified (in parenthesis).
511 .Bl -tag -width indent
513 Append text to the buffer after the addressed line.
514 Text is entered in input mode.
515 The current address is set to last line entered.
517 Change lines in the buffer.
518 The addressed lines are deleted
519 from the buffer, and text is appended in their place.
520 Text is entered in input mode.
521 The current address is set to last line entered.
523 Delete the addressed lines from the buffer.
524 If there is a line after the deleted range, then the current address is set
526 Otherwise the current address is set to the line
527 before the deleted range.
531 and sets the default filename.
534 is not specified, then the default filename is used.
535 Any lines in the buffer are deleted before
536 the new file is read.
537 The current address is set to the last line read.
539 Edit the standard output of
544 The default filename is unchanged.
545 Any lines in the buffer are deleted before the output of
548 The current address is set to the last line read.
553 This is similar to the
556 except that unwritten changes are discarded without warning.
557 The current address is set to the last line read.
559 Set the default filename to
563 is not specified, then the default unescaped filename is printed.
564 .It (1,$)g/re/command-list
567 to each of the addressed lines matching a regular expression
569 The current address is set to the
570 line currently matched before
575 command, the current address is set to the last line affected by
580 must be on a separate line,
581 and every line except for the last must be terminated by a backslash
583 Any commands are allowed, except for
595 Interactively edit the addressed lines matching a regular expression
597 For each matching line,
599 the current address is set,
600 and the user is prompted to enter a
604 command, the current address
605 is set to the last line affected by (the last)
610 is the same as that of the
613 A newline alone acts as a null command list.
616 repeats the last non-null command list.
618 Toggle the printing of error explanations.
619 By default, explanations are not printed.
620 It is recommended that ed scripts begin with this command to
623 Print an explanation of the last error.
625 Insert text in the buffer before the current line.
626 Text is entered in input mode.
627 The current address is set to the last line entered.
629 Join the addressed lines.
630 The addressed lines are
631 deleted from the buffer and replaced by a single
632 line containing their joined text.
633 The current address is set to the resultant line.
635 Mark a line with a lower case letter
637 The line can then be addressed as
639 (i.e., a single quote followed by
641 in subsequent commands.
642 The mark is not cleared until the line is
643 deleted or otherwise modified.
645 Print the addressed lines unambiguously.
646 If a single line fills more than one screen (as might be the case
647 when viewing a binary file, for instance), a
649 prompt is printed on the last line.
652 utility waits until the RETURN key is pressed
653 before displaying the next screen.
654 The current address is set to the last line
657 Move lines in the buffer.
658 The addressed lines are moved to after the
659 right-hand destination address, which may be the address
662 The current address is set to the
665 Print the addressed lines along with
667 The current address is set to the last line
670 Print the addressed lines.
671 The current address is set to the last line
674 Toggle the command prompt on and off.
675 Unless a prompt was specified by with command-line option
677 the command prompt is by default turned off.
685 This is similar to the
688 except that unwritten changes are discarded without warning.
692 to after the addressed line.
695 is not specified, then the default
697 If there was no default filename prior to the command,
698 then the default filename is set to
700 Otherwise, the default filename is unchanged.
701 The current address is set to the last line read.
704 to after the addressed line
705 the standard output of
710 The default filename is unchanged.
711 The current address is set to the last line read.
712 .It (.,.)s/re/replacement/
713 .It (.,.)s/re/replacement/g
714 .It (.,.)s/re/replacement/n
715 Replace text in the addressed lines
716 matching a regular expression
720 By default, only the first match in each line is replaced.
723 (global) suffix is given, then every match to be replaced.
728 is a positive number, causes only the
730 match to be replaced.
731 It is an error if no substitutions are performed on any of the addressed
733 The current address is set the last line affected.
738 may be delimited by any character other than space and newline
742 If one or two of the last delimiters is omitted, then the last line
743 affected is printed as though the print suffix
751 is replaced by the currently matched text.
752 The character sequence
756 is a number in the range [1,9], is replaced by the
758 backreference expression of the matched text.
765 from the last substitution is used.
766 Newlines may be embedded in
768 if they are escaped with a backslash (\\).
770 Repeat the last substitution.
773 command accepts a count suffix
775 or any combination of the characters
782 is given, then only the
788 the regular expression of the last search to be used instead of the
789 that of the last substitution.
792 suffix toggles the global suffix of the last substitution.
795 suffix toggles the print suffix of the last substitution
796 The current address is set to the last line affected.
798 Copy (i.e., transfer) the addressed lines to after the right-hand
799 destination address, which may be the address
802 The current address is set to the last line
805 Undo the last command and restores the current address
806 to what it was before the command.
813 are treated as a single command by undo.
816 .It (1,$)v/re/command-list
819 to each of the addressed lines not matching a regular expression
821 This is similar to the
825 Interactively edit the addressed lines not matching a regular expression
827 This is similar to the
831 Write the addressed lines to
833 Any previous contents of
835 is lost without warning.
836 If there is no default filename, then the default filename is set to
838 otherwise it is unchanged.
839 If no filename is specified, then the default
841 The current address is unchanged.
843 Write the addressed lines to
848 .It (1,$)w Ar !command
849 Write the addressed lines to the standard input of
854 The default filename and current address are unchanged.
856 Append the addressed lines to the end of
858 This is similar to the
860 command, expect that the previous contents of file is not clobbered.
861 The current address is unchanged.
865 lines at a time starting at addressed line.
868 is not specified, then the current window size is used.
869 The current address is set to the last line printed.
875 If the first character of
879 then it is replaced by text of the
884 utility does not process
886 for backslash (\\) escapes.
887 However, an unescaped
889 is replaced by the default filename.
890 When the shell returns from execution, a
892 is printed to the standard output.
893 The current line is unchanged.
895 Print the line number of the addressed line.
897 Print the addressed line, and sets the current address to
901 .Bl -tag -width /tmp/ed.* -compact
907 attempts to write the buffer if the terminal hangs up
910 When an error occurs,
914 and either returns to command mode
915 or exits if its input is from a script.
916 An explanation of the last error can be
923 (global) command masks any errors from failed searches and substitutions,
924 it can be used to perform conditional operations in scripts; e.g.,
934 replaces any occurrences of
940 (undo) command occurs in a global command list, then
941 the command list is executed only once.
943 If diagnostics are not disabled, attempting to quit
945 or edit another file before writing a modified buffer
947 If the command is entered a second time, it succeeds,
948 but any changes to the buffer are lost.
959 .%B Software Tools in Pascal
966 .%T A Tutorial Introduction to the UNIX Text Editor
971 .%T Advanced Editing on UNIX
978 arguments for backslash escapes, i.e., in a filename,
979 any characters preceded by a backslash (\\) are
980 interpreted literally.
982 If a text (non-binary) file is not terminated by a newline character,
985 appends one on reading/writing it.
986 In the case of a binary file,
988 does not append a newline on reading/writing.
990 per line overhead: 4 ints
999 utility does not recognize multibyte characters.