💾 Archived View for drewdevault.com › cgi-bin › man.sh › 1 › ed captured on 2022-03-01 at 17:10:27.
-=-=-=-=-=-=-
ED(1P) POSIX Programmer's Manual ED(1P) PROLOG This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME ed -- edit text SYNOPSIS ed [-p string] [-s] [file] DESCRIPTION The ed utility is a line-oriented text editor that uses two modes: command mode and input mode. In command mode the input characters shall be interpreted as commands, and in input mode they shall be interpreted as text. See the EXTENDED DESCRIPTION section. If an operand is '-', the results are unspecified. OPTIONS The ed utility shall conform to the Base Definitions volume of POSIX.1-2017, Section 12.2, Utility Syntax Guidelines, except for the unspecified usage of '-'. The following options shall be supported: -p string Use string as the prompt string when in command mode. By default, there shall be no prompt string. -s Suppress the writing of byte counts by e, E, r, and w commands and of the '!' prompt after a !command. OPERANDS The following operand shall be supported: file If the file argument is given, ed shall simulate an e command on the file named by the pathname, file, before accepting commands from the standard input. STDIN The standard input shall be a text file consisting of commands, as described in the EXTENDED DESCRIPTION section. INPUT FILES The input files shall be text files. ENVIRONMENT VARIABLES The following environment variables shall affect the execution of ed: HOME Determine the pathname of the user's home directory. LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regular expressions. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files) and the behavior of character classes within regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. ASYNCHRONOUS EVENTS The ed utility shall take the standard action for all signals (see the ASYNCHRONOUS EVENTS section in Section 1.4, Utility Description Defaults) with the following exceptions: SIGINT The ed utility shall interrupt its current activity, write the string "?\n" to standard output, and return to command mode (see the EXTENDED DESCRIPTION section). SIGHUP If the buffer is not empty and has changed since the last write, the ed utility shall attempt to write a copy of the buffer in a file. First, the file named ed.hup in the current directory shall be used; if that fails, the file named ed.hup in the directory named by the HOME environment variable shall be used. In any case, the ed utility shall exit without writing the file to the currently remembered pathname and without returning to command mode. SIGQUIT The ed utility shall ignore this event. STDOUT Various editing commands and the prompting feature (see -p) write to standard output, as described in the EXTENDED DESCRIPTION section. STDERR The standard error shall be used only for diagnostic messages. OUTPUT FILES The output files shall be text files whose formats are dependent on the editing commands given. EXTENDED DESCRIPTION The ed utility shall operate on a copy of the file it is editing; changes made to the copy shall have no effect on the file until a w (write) command is given. The copy of the text is called the buffer. Commands to ed have a simple and regular structure: zero, one, or two addresses followed by a single-character command, possibly followed by parameters to that command. These addresses specify one or more lines in the buffer. Every command that requires addresses has default addresses, so that the addresses very often can be omitted. If the -p option is specified, the prompt string shall be written to standard output before each command is read. In general, only one command can appear on a line. Certain commands allow text to be input. This text is placed in the appropriate place in the buffer. While ed is accepting text, it is said to be in input mode. In this mode, no commands shall be recognized; all input is merely collected. Input mode is terminated by entering a line consisting of two characters: a <period> ('.') followed by a <newline>. This line is not considered part of the input text. Regular Expressions in ed The ed utility shall support basic regular expressions, as described in the Base Definitions volume of POSIX.1-2017, Section 9.3, Basic Regular Expressions. Since regular expressions in ed are always matched against single lines (excluding the terminating <newline> characters), never against any larger section of text, there is no way for a regular expression to match a <newline>. A null RE shall be equivalent to the last RE encountered. Regular expressions are used in addresses to specify lines, and in some commands (for example, the s substitute command) to specify portions of a line to be substituted. Addresses in ed Addressing in ed relates to the current line. Generally, the current line is the last line affected by a command. The current line number is the address of the current line. If the edit buffer is not empty, the initial value for the current line shall be the last line in the edit buffer; otherwise, zero. Addresses shall be constructed as follows: 1. The <period> character ('.') shall address the current line. 2. The <dollar-sign> character ('