23 utility is a line-oriented text editor.
24 It is used to create, display, modify and otherwise manipulate text
30 mode, in which the only difference is that the editor restricts the
31 use of filenames which start with
33 (interpreted as shell commands by
37 Note that editing outside of the current directory is only prohibited
38 if the user does not have write access to the current directory.
39 If a user has write access to the current directory, then symbolic
40 links can be created in the current directory, in which case
42 will not stop the user from editing the file that the symbolic link
47 argument, then a copy of
49 is read into the editor's buffer.
50 Changes are made to this copy and not directly to
55 any changes not explicitly saved with a
59 Editing is done in two distinct modes:
66 In this mode commands are read from the standard input and
67 executed to manipulate the contents of the editor buffer.
68 A typical command might look like:
77 which replaces all occurrences of the string
82 When an input command, such as
91 This is the primary means
92 of adding text to a file.
93 In this mode, no commands are available;
94 instead, the standard input is written
95 directly to the editor buffer.
96 Lines consist of text up to and
100 Input mode is terminated by
101 entering a single period
107 commands operate on whole lines or ranges of lines; e.g.,
110 command deletes lines; the
112 command moves lines, and so on.
113 It is possible to modify only a portion of a line by means of replacement,
114 as in the example above.
115 However even here, the
117 command is applied to whole lines at a time.
121 commands consist of zero or more line addresses, followed by a single
122 character command and possibly additional parameters; i.e.,
123 commands have the structure:
127 .Op Ar address Op , Ar address
128 .Ar command Op Ar parameters
132 The address(es) indicate the line or range of lines to be affected by the
134 If fewer addresses are given than the command accepts, then
135 default addresses are supplied.
137 The following options are available:
138 .Bl -tag -width indent
140 Suppress diagnostics.
141 This should be used if
143 standard input is from a script.
145 Specify a command prompt.
146 This may be toggled on and off with the
150 Specify the name of a file to read.
154 bang (!), then it is interpreted as a shell command.
157 the standard output of
161 To read a file whose name begins with a bang, prefix the
162 name with a backslash (\\).
163 The default filename is set to
165 only if it is not prefixed with a bang.
168 An address represents the number of a line in the buffer.
174 typically supplied to commands as the default address when none is specified.
175 When a file is first read, the current address is set to the last line
177 In general, the current address is set to the last line
178 affected by a command.
181 constructed from one of the bases in the list below, optionally followed
183 The offset may include any combination
184 of digits, operators (i.e.,
190 Addresses are read from left to right, and their values are computed
191 relative to the current address.
193 One exception to the rule that addresses represent line numbers is the
197 This means "before the first line,"
198 and is legal wherever it makes sense.
200 An address range is two addresses separated either by a comma or
202 The value of the first address in a range cannot exceed the
204 If only one address is given in a range, then
205 the second address is set to the given address.
208 of addresses is given where
210 then the corresponding range is determined by the last two addresses in
213 If only one address is expected, then the last address is used.
215 Each address in a comma-delimited range is interpreted relative to the
217 In a semi-colon-delimited range, the first address is
218 used to set the current address, and the second address is interpreted
219 relative to the first.
221 The following address symbols are recognized:
222 .Bl -tag -width indent
224 The current line (address) in the buffer.
226 The last line in the buffer.
233 is a number in the range
237 This is equivalent to
239 and may be repeated with cumulative effect.
245 is a non-negative number.
248 This is equivalent to
250 and may be repeated with cumulative effect.
256 is a non-negative number.
258 The first through last lines in the buffer.
259 This is equivalent to
263 The current through last lines in the buffer.
264 This is equivalent to
268 The next line containing the regular expression
270 The search wraps to the beginning of the buffer and continues down to the
271 current line, if necessary.
272 // repeats the last search.
275 previous line containing the regular expression
277 The search wraps to the end of the buffer and continues up to the
278 current line, if necessary.
279 ?? repeats the last search.
282 line previously marked by a
284 (mark) command, where
286 is a lower case letter.
288 .Sh REGULAR EXPRESSIONS
289 Regular expressions are patterns used in selecting text.
290 For example, the command:
293 .Cm g No / Em string Xo
298 prints all lines containing
300 Regular expressions are also
303 command for selecting old text to be replaced with new.
305 In addition to a specifying string literals, regular expressions can
308 Strings thus represented are said to be matched
309 by the corresponding regular expression.
310 If it is possible for a regular expression
311 to match several strings in a line, then the left-most longest match is
314 The following symbols are used in constructing regular expressions:
315 .Bl -tag -width indent
319 not listed below, including
329 Any backslash-escaped character
341 Match any single character.
343 Match any single character in
349 it must be the first character.
350 A range of characters may be specified by separating the end characters
355 specifies the lower case characters.
356 The following literal expressions can also be used in
358 to specify sets of characters:
360 .Bl -column "[:alnum:]" "[:cntrl:]" "[:lower:]" "[:xdigit:]" -compact
361 .It [:alnum:] Ta [:cntrl:] Ta [:lower:] Ta [:space:]
362 .It [:alpha:] Ta [:digit:] Ta [:print:] Ta [:upper:]
363 .It [:blank:] Ta [:graph:] Ta [:punct:] Ta [:xdigit:]
368 appears as the first or last
371 then it matches itself.
372 All other characters in
380 .Bl -item -compact -offset 2n
382 .Op \&. Ns Ar col-elm Ns .\&
385 .Op = Ns Ar col-elm Ns =
391 .Em collating element
392 are interpreted according to the current locale settings
393 (not currently supported).
398 for an explanation of these constructs.
400 Match any single character, other than newline, not in
408 is the first character of a regular expression, then it
409 anchors the regular expression to the beginning of a line.
410 Otherwise, it matches itself.
414 is the last character of a regular expression, it
415 anchors the regular expression to the end of a line.
416 Otherwise, it matches itself.
418 Anchor the single character regular expression or subexpression
419 immediately following it to the beginning of a word.
420 (This may not be available)
422 Anchor the single character regular expression or subexpression
423 immediately following it to the end of a word.
424 (This may not be available)
426 Define a subexpression
428 Subexpressions may be nested.
429 A subsequent backreference of the form
433 is a number in the range [1,9], expands to the text matched by the
436 For example, the regular expression
439 consisting of identical adjacent substrings.
440 Subexpressions are ordered relative to
441 their left delimiter.
443 Match the single character regular expression or subexpression
444 immediately preceding it zero or more times.
448 character of a regular expression or subexpression, then it matches
452 operator sometimes yields unexpected results.
453 For example, the regular expression
455 matches the beginning of
458 (as opposed to the substring
461 is the only left-most match.
462 .It \e{n,m\e} or \e{n,\e} or \e{n\e}
463 Match the single character regular expression or subexpression
464 immediately preceding it at least
471 is omitted, then it matches at least
474 If the comma is also omitted, then it matches exactly
479 Additional regular expression operators may be defined depending on the
486 commands are single characters, though some require additional parameters.
487 If a command's parameters extend over several lines, then
488 each line except for the last
489 must be terminated with a backslash (\\).
491 In general, at most one command is allowed per line.
492 However, most commands accept a print suffix, which is any of
500 to print the last line affected by the command.
502 An interrupt (typically ^C) has the effect of aborting the current command
503 and returning the editor to command mode.
508 recognizes the following commands.
509 The commands are shown together with
510 the default address or address range supplied if none is
511 specified (in parenthesis).
512 .Bl -tag -width indent
514 Append text to the buffer after the addressed line.
515 Text is entered in input mode.
516 The current address is set to last line entered.
518 Change lines in the buffer.
519 The addressed lines are deleted
520 from the buffer, and text is appended in their place.
521 Text is entered in input mode.
522 The current address is set to last line entered.
524 Delete the addressed lines from the buffer.
525 If there is a line after the deleted range, then the current address is set
527 Otherwise the current address is set to the line
528 before the deleted range.
532 and sets the default filename.
535 is not specified, then the default filename is used.
536 Any lines in the buffer are deleted before
537 the new file is read.
538 The current address is set to the last line read.
540 Edit the standard output of
545 The default filename is unchanged.
546 Any lines in the buffer are deleted before the output of
549 The current address is set to the last line read.
554 This is similar to the
557 except that unwritten changes are discarded without warning.
558 The current address is set to the last line read.
560 Set the default filename to
564 is not specified, then the default unescaped filename is printed.
565 .It (1,$)g/re/command-list
568 to each of the addressed lines matching a regular expression
570 The current address is set to the
571 line currently matched before
576 command, the current address is set to the last line affected by
581 must be on a separate line,
582 and every line except for the last must be terminated by a backslash
584 Any commands are allowed, except for
596 Interactively edit the addressed lines matching a regular expression
598 For each matching line,
600 the current address is set,
601 and the user is prompted to enter a
605 command, the current address
606 is set to the last line affected by (the last)
611 is the same as that of the
614 A newline alone acts as a null command list.
617 repeats the last non-null command list.
619 Toggle the printing of error explanations.
620 By default, explanations are not printed.
621 It is recommended that ed scripts begin with this command to
624 Print an explanation of the last error.
626 Insert text in the buffer before the current line.
627 Text is entered in input mode.
628 The current address is set to the last line entered.
630 Join the addressed lines.
631 The addressed lines are
632 deleted from the buffer and replaced by a single
633 line containing their joined text.
634 The current address is set to the resultant line.
636 Mark a line with a lower case letter
638 The line can then be addressed as
640 (i.e., a single quote followed by
642 in subsequent commands.
643 The mark is not cleared until the line is
644 deleted or otherwise modified.
646 Print the addressed lines unambiguously.
647 If a single line fills more than one screen (as might be the case
648 when viewing a binary file, for instance), a
650 prompt is printed on the last line.
653 utility waits until the RETURN key is pressed
654 before displaying the next screen.
655 The current address is set to the last line
658 Move lines in the buffer.
659 The addressed lines are moved to after the
660 right-hand destination address, which may be the address
663 The current address is set to the
666 Print the addressed lines along with
668 The current address is set to the last line
671 Print the addressed lines.
672 The current address is set to the last line
675 Toggle the command prompt on and off.
676 Unless a prompt was specified by with command-line option
678 the command prompt is by default turned off.
686 This is similar to the
689 except that unwritten changes are discarded without warning.
693 to after the addressed line.
696 is not specified, then the default
698 If there was no default filename prior to the command,
699 then the default filename is set to
701 Otherwise, the default filename is unchanged.
702 The current address is set to the last line read.
705 to after the addressed line
706 the standard output of
711 The default filename is unchanged.
712 The current address is set to the last line read.
713 .It (.,.)s/re/replacement/
714 .It (.,.)s/re/replacement/g
715 .It (.,.)s/re/replacement/n
716 Replace text in the addressed lines
717 matching a regular expression
721 By default, only the first match in each line is replaced.
724 (global) suffix is given, then every match to be replaced.
729 is a positive number, causes only the
731 match to be replaced.
732 It is an error if no substitutions are performed on any of the addressed
734 The current address is set the last line affected.
739 may be delimited by any character other than space and newline
743 If one or two of the last delimiters is omitted, then the last line
744 affected is printed as though the print suffix
752 is replaced by the currently matched text.
753 The character sequence
757 is a number in the range [1,9], is replaced by the
759 backreference expression of the matched text.
766 from the last substitution is used.
767 Newlines may be embedded in
769 if they are escaped with a backslash (\\).
771 Repeat the last substitution.
774 command accepts a count suffix
776 or any combination of the characters
783 is given, then only the
789 the regular expression of the last search to be used instead of the
790 that of the last substitution.
793 suffix toggles the global suffix of the last substitution.
796 suffix toggles the print suffix of the last substitution
797 The current address is set to the last line affected.
799 Copy (i.e., transfer) the addressed lines to after the right-hand
800 destination address, which may be the address
803 The current address is set to the last line
806 Undo the last command and restores the current address
807 to what it was before the command.
814 are treated as a single command by undo.
817 .It (1,$)v/re/command-list
820 to each of the addressed lines not matching a regular expression
822 This is similar to the
826 Interactively edit the addressed lines not matching a regular expression
828 This is similar to the
832 Write the addressed lines to
834 Any previous contents of
836 is lost without warning.
837 If there is no default filename, then the default filename is set to
839 otherwise it is unchanged.
840 If no filename is specified, then the default
842 The current address is unchanged.
844 Write the addressed lines to
849 .It (1,$)w Ar !command
850 Write the addressed lines to the standard input of
855 The default filename and current address are unchanged.
857 Append the addressed lines to the end of
859 This is similar to the
861 command, expect that the previous contents of file is not clobbered.
862 The current address is unchanged.
866 lines at a time starting at addressed line.
869 is not specified, then the current window size is used.
870 The current address is set to the last line printed.
876 If the first character of
880 then it is replaced by text of the
885 utility does not process
887 for backslash (\\) escapes.
888 However, an unescaped
890 is replaced by the default filename.
891 When the shell returns from execution, a
893 is printed to the standard output.
894 The current line is unchanged.
896 Print the line number of the addressed line.
898 Print the addressed line, and sets the current address to
902 .Bl -tag -width /tmp/ed.* -compact
908 attempts to write the buffer if the terminal hangs up
911 When an error occurs,
915 and either returns to command mode
916 or exits if its input is from a script.
917 An explanation of the last error can be
924 (global) command masks any errors from failed searches and substitutions,
925 it can be used to perform conditional operations in scripts; e.g.,
935 replaces any occurrences of
941 (undo) command occurs in a global command list, then
942 the command list is executed only once.
944 If diagnostics are not disabled, attempting to quit
946 or edit another file before writing a modified buffer
948 If the command is entered a second time, it succeeds,
949 but any changes to the buffer are lost.
960 .%B Software Tools in Pascal
969 arguments for backslash escapes, i.e., in a filename,
970 any characters preceded by a backslash (\\) are
971 interpreted literally.
973 If a text (non-binary) file is not terminated by a newline character,
976 appends one on reading/writing it.
977 In the case of a binary file,
979 does not append a newline on reading/writing.
981 per line overhead: 4 ints
990 utility does not recognize multibyte characters.