ED(1)                      POSIX Programmer's Manual                     ED(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       ed -- edit text

SSYYNNOOPPSSIISS
       ed [[-p _s_t_r_i_n_g]] [[-s]] [[_f_i_l_e]]

DDEESSCCRRIIPPTTIIOONN
       The _e_d utility is a line-oriented text editor that uses two modes:
       _c_o_m_m_a_n_d _m_o_d_e and _i_n_p_u_t _m_o_d_e.  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.

OOPPTTIIOONNSS
       The _e_d utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s, except for the
       unspecified usage of ''--''.

       The following options shall be supported:

       --pp _s_t_r_i_n_g Use _s_t_r_i_n_g as the prompt string when in command mode. By
                 default, there shall be no prompt string.

       --ss        Suppress the writing of byte counts by ee, EE, rr, and ww
                 commands and of the ''!!''  prompt after a !_c_o_m_m_a_n_d.

OOPPEERRAANNDDSS
       The following operand shall be supported:

       _f_i_l_e      If the _f_i_l_e argument is given, _e_d shall simulate an ee command
                 on the file named by the pathname, _f_i_l_e, before accepting
                 commands from the standard input.

SSTTDDIINN
       The standard input shall be a text file consisting of commands, as
       described in the EXTENDED DESCRIPTION section.

IINNPPUUTT FFIILLEESS
       The input files shall be text files.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _e_d:

       _H_O_M_E      Determine the pathname of the user's home directory.

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_O_L_L_A_T_E
                 Determine the locale for the behavior of ranges, equivalence
                 classes, and multi-character collating elements within
                 regular expressions.

       _L_C___C_T_Y_P_E  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.

       _L_C___M_E_S_S_A_G_E_S
                 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.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       The _e_d utility shall take the standard action for all signals (see the
       ASYNCHRONOUS EVENTS section in _S_e_c_t_i_o_n _1_._4, _U_t_i_l_i_t_y _D_e_s_c_r_i_p_t_i_o_n
       _D_e_f_a_u_l_t_s) with the following exceptions:

       SIGINT    The _e_d utility shall interrupt its current activity, write
                 the string ""??\\nn"" 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 _e_d utility shall attempt to write a copy of the
                 buffer in a file. First, the file named eedd..hhuupp in the current
                 directory shall be used; if that fails, the file named eedd..hhuupp
                 in the directory named by the _H_O_M_E environment variable shall
                 be used. In any case, the _e_d utility shall exit without
                 writing the file to the currently remembered pathname and
                 without returning to command mode.

       SIGQUIT   The _e_d utility shall ignore this event.

SSTTDDOOUUTT
       Various editing commands and the prompting feature (see --pp) write to
       standard output, as described in the EXTENDED DESCRIPTION section.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       The output files shall be text files whose formats are dependent on the
       editing commands given.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       The _e_d 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 ww
       (write) command is given. The copy of the text is called the _b_u_f_f_e_r.

       Commands to _e_d have a simple and regular structure: zero, one, or two
       _a_d_d_r_e_s_s_e_s followed by a single-character _c_o_m_m_a_n_d, 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 --pp
       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 _e_d is accepting text, it is said to be in _i_n_p_u_t _m_o_d_e.
       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.

   RReegguullaarr EExxpprreessssiioonnss iinn eedd
       The _e_d utility shall support basic regular expressions, as described in
       the Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _9_._3, _B_a_s_i_c _R_e_g_u_l_a_r
       _E_x_p_r_e_s_s_i_o_n_s.  Since regular expressions in _e_d 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 ss substitute command) to specify portions of
       a line to be substituted.

   AAddddrreesssseess iinn eedd
       Addressing in _e_d 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 (''$$'') shall address the last line of
           the edit buffer.

        3. The positive decimal number _n shall address the _nth line of the
           edit buffer.

        4. The <apostrophe>-x character pair (""''xx"") shall address the line
           marked with the mark name character _x, which shall be a lowercase
           letter from the portable character set. It shall be an error if the
           character has not been set to mark a line or if the line that was
           marked is not currently present in the edit buffer.

        5. A BRE enclosed by <slash> characters (''//'') shall address the first
           line found by searching forwards from the line following the
           current line toward the end of the edit buffer and stopping at the
           first line for which the line excluding the terminating <newline>
           matches the BRE. The BRE consisting of a null BRE delimited by a
           pair of <slash> characters shall address the next line for which
           the line excluding the terminating <newline> matches the last BRE
           encountered. In addition, the second <slash> can be omitted at the
           end of a command line. Within the BRE, a <backslash>-<slash> pair
           (""\\//"") shall represent a literal <slash> instead of the BRE
           delimiter. If necessary, the search shall wrap around to the
           beginning of the buffer and continue up to and including the
           current line, so that the entire buffer is searched.

        6. A BRE enclosed by <question-mark> characters (''??'')  shall address
           the first line found by searching backwards from the line preceding
           the current line toward the beginning of the edit buffer and
           stopping at the first line for which the line excluding the
           terminating <newline> matches the BRE. The BRE consisting of a null
           BRE delimited by a pair of <question-mark> characters (""????"") shall
           address the previous line for which the line excluding the
           terminating <newline> matches the last BRE encountered. In
           addition, the second <question-mark> can be omitted at the end of a
           command line. Within the BRE, a <backslash>-<question-mark> pair
           (""\\??"") shall represent a literal <question-mark> instead of the BRE
           delimiter. If necessary, the search shall wrap around to the end of
           the buffer and continue up to and including the current line, so
           that the entire buffer is searched.

        7. A <plus-sign> (''++'') or <hyphen-minus> character (''--'') followed by a
           decimal number shall address the current line plus or minus the
           number. A <plus-sign> or <hyphen-minus> character not followed by a
           decimal number shall address the current line plus or minus 1.

       Addresses can be followed by zero or more address offsets, optionally
       <blank>-separated.  Address offsets are constructed as follows:

        *  A <plus-sign> or <hyphen-minus> character followed by a decimal
           number shall add or subtract, respectively, the indicated number of
           lines to or from the address. A <plus-sign> or <hyphen-minus>
           character not followed by a decimal number shall add or subtract 1
           to or from the address.

        *  A decimal number shall add the indicated number of lines to the
           address.

       It shall not be an error for an intermediate address value to be less
       than zero or greater than the last line in the edit buffer. It shall be
       an error for the final address value to be less than zero or greater
       than the last line in the edit buffer. It shall be an error if a search
       for a BRE fails to find a matching line.

       Commands accept zero, one, or two addresses. If more than the required
       number of addresses are provided to a command that requires zero
       addresses, it shall be an error. Otherwise, if more than the required
       number of addresses are provided to a command, the addresses specified
       first shall be evaluated and then discarded until the maximum number of
       valid addresses remain, for the specified command.

       Addresses shall be separated from each other by a <comma> ('',,'') or
       <semicolon> character ('';;'').  In the case of a <semicolon> separator,
       the current line (''..'')  shall be set to the first address, and only
       then will the second address be calculated. This feature can be used to
       determine the starting line for forwards and backwards searches; see
       rules 5. and 6.

       Addresses can be omitted on either side of the <comma> or <semicolon>
       separator, in which case the resulting address pairs shall be as
       follows:

                              +----------+-------------+
                              |SSppeecciiffiieedd |  RReessuullttiinngg  |
                              +----------+-------------+
                              |,         | 1 , $       |
                              |, addr    | 1 , addr    |
                              |addr ,    | addr , addr |
                              |;         | . ; $       |
                              |; addr    | . ; addr    |
                              |addr ;    | addr ; addr |
                              +----------+-------------+
       Any <blank> characters included between addresses, address separators,
       or address offsets shall be ignored.

   CCoommmmaannddss iinn eedd
       In the following list of _e_d commands, the default addresses are shown
       in parentheses. The number of addresses shown in the default shall be
       the number expected by the command. The parentheses are not part of the
       address; they show that the given addresses are the default.

       It is generally invalid for more than one command to appear on a line.
       However, any command (except ee, EE, ff, qq, QQ, rr, ww, and !!)  can be
       suffixed by the letter ll, nn, or pp; in which case, except for the ll, nn,
       and pp commands, the command shall be executed and then the new current
       line shall be written as described below under the ll, nn, and pp
       commands. When an ll, nn, or pp suffix is used with an ll, nn, or pp command,
       the command shall write to standard output as described below, but it
       is unspecified whether the suffix writes the current line again in the
       requested format or whether the suffix has no effect. For example, the
       ppll command (base pp command with an ll suffix) shall either write just
       the current line or write it twice--once as specified for pp and once as
       specified for ll.  Also, the gg, GG, vv, and VV commands shall take a
       command as a parameter.

       Each address component can be preceded by zero or more <blank>
       characters. The command letter can be preceded by zero or more <blank>
       characters. If a suffix letter (ll, nn, or pp) is given, the application
       shall ensure that it immediately follows the command.

       The ee, EE, ff, rr, and ww commands shall take an optional _f_i_l_e parameter,
       separated from the command letter by one or more <blank> characters.

       If changes have been made in the buffer since the last ww command that
       wrote the entire buffer, _e_d shall warn the user if an attempt is made
       to destroy the editor buffer via the ee or qq commands. The _e_d utility
       shall write the string:


           "?\n"

       (followed by an explanatory message if _h_e_l_p _m_o_d_e has been enabled via
       the HH command) to standard output and shall continue in command mode
       with the current line number unchanged. If the ee or qq command is
       repeated with no intervening command, it shall take effect.

       If a terminal disconnect (see the Base Definitions volume of
       POSIX.1-2017, _C_h_a_p_t_e_r _1_1, _G_e_n_e_r_a_l _T_e_r_m_i_n_a_l _I_n_t_e_r_f_a_c_e, Modem Disconnect
       and Closing a Device Terminal), is detected:

        *  If accompanied by a SIGHUP signal, the _e_d utility shall operate as
           described in the ASYNCHRONOUS EVENTS section for a SIGHUP signal.

        *  If not accompanied by a SIGHUP signal, the _e_d utility shall act as
           if an end-of-file had been detected on standard input.

       If an end-of-file is detected on standard input:

        *  If the _e_d utility is in input mode, _e_d shall terminate input mode
           and return to command mode. It is unspecified if any partially
           entered lines (that is, input text without a terminating <newline>)
           are discarded from the input text.

        *  If the _e_d utility is in command mode, it shall act as if a qq
           command had been entered.

       If the closing delimiter of an RE or of a replacement string (for
       example, ''//'') in a gg, GG, ss, vv, or VV command would be the last character
       before a <newline>, that delimiter can be omitted, in which case the
       addressed line shall be written. For example, the following pairs of
       commands are equivalent:


           s/s1/s2   s/s1/s2/p
           g/s1      g/s1/p
           ?s1       ?s1?

       If an invalid command is entered, _e_d shall write the string:


           "?\n"

       (followed by an explanatory message if _h_e_l_p _m_o_d_e has been enabled via
       the HH command) to standard output and shall continue in command mode
       with the current line number unchanged.

   AAppppeenndd CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.)a
                     <_t_e_x_t>
                     .

       The aa command shall read the given text and append it after the
       addressed line; the current line number shall become the address of the
       last inserted line or, if there were none, the addressed line. Address
       0 shall be valid for this command; it shall cause the appended text to
       be placed at the beginning of the buffer.

   CChhaannggee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)c
                     <_t_e_x_t>
                     .

       The cc command shall delete the addressed lines, then accept input text
       that replaces these lines; the current line shall be set to the address
       of the last line input; or, if there were none, at the line after the
       last line deleted; if the lines deleted were originally at the end of
       the buffer, the current line number shall be set to the address of the
       new last line; if no lines remain in the buffer, the current line
       number shall be set to zero. Address 0 shall be valid for this command;
       it shall be interpreted as if address 1 were specified.

   DDeelleettee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)d

       The dd command shall delete the addressed lines from the buffer. The
       address of the line after the last line deleted shall become the
       current line number; if the lines deleted were originally at the end of
       the buffer, the current line number shall be set to the address of the
       new last line; if no lines remain in the buffer, the current line
       number shall be set to zero.

   EEddiitt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     e [[_f_i_l_e]]

       The ee command shall delete the entire contents of the buffer and then
       read in the file named by the pathname _f_i_l_e.  The current line number
       shall be set to the address of the last line of the buffer. If no
       pathname is given, the currently remembered pathname, if any, shall be
       used (see the ff command). The number of bytes read shall be written to
       standard output, unless the --ss option was specified, in the following
       format:


           "%d\n", <_n_u_m_b_e_r _o_f _b_y_t_e_s _r_e_a_d>

       The name _f_i_l_e shall be remembered for possible use as a default
       pathname in subsequent ee, EE, rr, and ww commands. If _f_i_l_e is replaced by
       ''!!'', the rest of the line shall be taken to be a shell command line
       whose output is to be read. Such a shell command line shall not be
       remembered as the current _f_i_l_e.  All marks shall be discarded upon the
       completion of a successful ee command. If the buffer has changed since
       the last time the entire buffer was written, the user shall be warned,
       as described previously.

   EEddiitt WWiitthhoouutt CChheecckkiinngg CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     E [[_f_i_l_e]]

       The EE command shall possess all properties and restrictions of the ee
       command except that the editor shall not check to see whether any
       changes have been made to the buffer since the last ww command.

   FFiilleennaammee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     f [[_f_i_l_e]]

       If _f_i_l_e is given, the ff command shall change the currently remembered
       pathname to _f_i_l_e; whether the name is changed or not, it shall then
       write the (possibly new) currently remembered pathname to the standard
       output in the following format:


           "%s\n", <_p_a_t_h_n_a_m_e>

       The current line number shall be unchanged.

   GGlloobbaall CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (1,$)g/_R_E/_c_o_m_m_a_n_d _l_i_s_t

       In the gg command, the first step shall be to mark every line for which
       the line excluding the terminating <newline> matches the given RE.
       Then, going sequentially from the beginning of the file to the end of
       the file, the given _c_o_m_m_a_n_d _l_i_s_t shall be executed for each marked
       line, with the current line number set to the address of that line. Any
       line modified by the _c_o_m_m_a_n_d _l_i_s_t shall be unmarked. When the gg command
       completes, the current line number shall have the value assigned by the
       last command in the _c_o_m_m_a_n_d _l_i_s_t.  If there were no matching lines, the
       current line number shall not be changed. A single command or the first
       of a list of commands shall appear on the same line as the global
       command. All lines of a multi-line list except the last line shall be
       ended with a <backslash> preceding the terminating <newline>; the aa, ii,
       and cc commands and associated input are permitted. The ''..''  terminating
       input mode can be omitted if it would be the last line of the _c_o_m_m_a_n_d
       _l_i_s_t. An empty _c_o_m_m_a_n_d _l_i_s_t shall be equivalent to the pp command. The
       use of the gg, GG, vv, VV, and !!  commands in the _c_o_m_m_a_n_d _l_i_s_t produces
       undefined results. Any character other than <space> or <newline> can be
       used instead of a <slash> to delimit the RE. Within the RE, the RE
       delimiter itself can be used as a literal character if it is preceded
       by a <backslash>.

   IInntteerraaccttiivvee GGlloobbaall CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (1,$)G/_R_E/

       In the GG command, the first step shall be to mark every line for which
       the line excluding the terminating <newline> matches the given RE.
       Then, for every such line, that line shall be written, the current line
       number shall be set to the address of that line, and any one command
       (other than one of the aa, cc, ii, gg, GG, vv, and VV commands) shall be read
       and executed. A <newline> shall act as a null command (causing no
       action to be taken on the current line); an ''&&'' shall cause the re-
       execution of the most recent non-null command executed within the
       current invocation of GG.  Note that the commands input as part of the
       execution of the GG command can address and affect any lines in the
       buffer. Any line modified by the command shall be unmarked. The final
       value of the current line number shall be the value set by the last
       command successfully executed. (Note that the last command successfully
       executed shall be the GG command itself if a command fails or the null
       command is specified.) If there were no matching lines, the current
       line number shall not be changed. The GG command can be terminated by a
       SIGINT signal. Any character other than <space> or <newline> can be
       used instead of a <slash> to delimit the RE and the replacement. Within
       the RE, the RE delimiter itself can be used as a literal character if
       it is preceded by a <backslash>.

   HHeellpp CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     h

       The hh command shall write a short message to standard output that
       explains the reason for the most recent ''??''  notification. The current
       line number shall be unchanged.

   HHeellpp--MMooddee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     H

       The HH command shall cause _e_d to enter a mode in which help messages
       (see the hh command) shall be written to standard output for all
       subsequent ''??''  notifications. The HH command alternately shall turn
       this mode on and off; it is initially off. If the help-mode is being
       turned on, the HH command also explains the previous ''??''  notification,
       if there was one. The current line number shall be unchanged.

   IInnsseerrtt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.)i
                     <_t_e_x_t>
                     .

       The ii command shall insert the given text before the addressed line;
       the current line is set to the last inserted line or, if there was
       none, to the addressed line. This command differs from the aa command
       only in the placement of the input text. Address 0 shall be valid for
       this command; it shall be interpreted as if address 1 were specified.

   JJooiinn CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.+1)j

       The jj command shall join contiguous lines by removing the appropriate
       <newline> characters. If exactly one address is given, this command
       shall do nothing. If lines are joined, the current line number shall be
       set to the address of the joined line; otherwise, the current line
       number shall be unchanged.

   MMaarrkk CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.)k_x

       The kk command shall mark the addressed line with name _x, which the
       application shall ensure is a lowercase letter from the portable
       character set. The address ""''xx"" shall then refer to this line; the
       current line number shall be unchanged.

   LLiisstt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)l

       The ll command shall write to standard output the addressed lines in a
       visually unambiguous form. The characters listed in the Base
       Definitions volume of POSIX.1-2017, _T_a_b_l_e _5_-_1, _E_s_c_a_p_e _S_e_q_u_e_n_c_e_s _a_n_d
       _A_s_s_o_c_i_a_t_e_d _A_c_t_i_o_n_s (''\\\\'', ''\\aa'', ''\\bb'', ''\\ff'', ''\\rr'', ''\\tt'', ''\\vv'') shall be
       written as the corresponding escape sequence; the ''\\nn'' in that table is
       not applicable. Non-printable characters not in the table shall be
       written as one three-digit octal number (with a preceding <backslash>
       character) for each byte in the character (most significant byte
       first).

       Long lines shall be folded, with the point of folding indicated by
       <newline> preceded by a <backslash>; the length at which folding occurs
       is unspecified, but should be appropriate for the output device. The
       end of each line shall be marked with a ''$$'', and ''$$'' characters within
       the text shall be written with a preceding <backslash>.  An ll command
       can be appended to any other command other than ee, EE, ff, qq, QQ, rr, ww, or
       !!.  The current line number shall be set to the address of the last
       line written.

   MMoovvee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)m_a_d_d_r_e_s_s

       The mm command shall reposition the addressed lines after the line
       addressed by _a_d_d_r_e_s_s.  Address 0 shall be valid for _a_d_d_r_e_s_s and cause
       the addressed lines to be moved to the beginning of the buffer. It
       shall be an error if address _a_d_d_r_e_s_s falls within the range of moved
       lines. The current line number shall be set to the address of the last
       line moved.

   NNuummbbeerr CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)n

       The nn command shall write to standard output the addressed lines,
       preceding each line by its line number and a <tab>; the current line
       number shall be set to the address of the last line written. The nn
       command can be appended to any command other than ee, EE, ff, qq, QQ, rr, ww,
       or !!.

   PPrriinntt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)p

       The pp command shall write to standard output the addressed lines; the
       current line number shall be set to the address of the last line
       written. The pp command can be appended to any command other than ee, EE,
       ff, qq, QQ, rr, ww, or !!.

   PPrroommpptt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     P

       The PP command shall cause _e_d to prompt with an <asterisk> (''**'') (or
       _s_t_r_i_n_g, if --pp is specified) for all subsequent commands. The PP command
       alternatively shall turn this mode on and off; it shall be initially on
       if the --pp option is specified; otherwise, off. The current line number
       shall be unchanged.

   QQuuiitt CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     q

       The qq command shall cause _e_d to exit. If the buffer has changed since
       the last time the entire buffer was written, the user shall be warned,
       as described previously.

   QQuuiitt WWiitthhoouutt CChheecckkiinngg CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     Q

       The QQ command shall cause _e_d to exit without checking whether changes
       have been made in the buffer since the last ww command.

   RReeaadd CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     ($)r [[_f_i_l_e]]

       The rr command shall read in the file named by the pathname _f_i_l_e and
       append it after the addressed line. If no _f_i_l_e argument is given, the
       currently remembered pathname, if any, shall be used (see the ee and ff
       commands). The currently remembered pathname shall not be changed
       unless there is no remembered pathname. Address 0 shall be valid for rr
       and shall cause the file to be read at the beginning of the buffer. If
       the read is successful, and --ss was not specified, the number of bytes
       read shall be written to standard output in the following format:


           "%d\n", <_n_u_m_b_e_r _o_f _b_y_t_e_s _r_e_a_d>

       The current line number shall be set to the address of the last line
       read in. If _f_i_l_e is replaced by ''!!'', the rest of the line shall be
       taken to be a shell command line whose output is to be read. Such a
       shell command line shall not be remembered as the current pathname.

   SSuubbssttiittuuttee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)s/_R_E/_r_e_p_l_a_c_e_m_e_n_t/_f_l_a_g_s

       The ss command shall search each addressed line for an occurrence of the
       specified RE and replace either the first or all (non-overlapped)
       matched strings with the _r_e_p_l_a_c_e_m_e_n_t; see the following description of
       the gg suffix. It is an error if the substitution fails on every
       addressed line. Any character other than <space> or <newline> can be
       used instead of a <slash> to delimit the RE and the replacement. Within
       the RE, the RE delimiter itself can be used as a literal character if
       it is preceded by a <backslash>.  The current line shall be set to the
       address of the last line on which a substitution occurred.

       An <ampersand> (''&&'') appearing in the _r_e_p_l_a_c_e_m_e_n_t shall be replaced by
       the string matching the RE on the current line.  The special meaning of
       ''&&'' in this context can be suppressed by preceding it by <backslash>.
       As a more general feature, the characters ''\\nn'', where _n is a digit,
       shall be replaced by the text matched by the corresponding back-
       reference expression. If the corresponding back-reference expression
       does not match, then the characters ''\\nn'' shall be replaced by the empty
       string. When the character ''%%'' is the only character in the
       _r_e_p_l_a_c_e_m_e_n_t, the _r_e_p_l_a_c_e_m_e_n_t used in the most recent substitute command
       shall be used as the _r_e_p_l_a_c_e_m_e_n_t in the current substitute command; if
       there was no previous substitute command, the use of ''%%'' in this manner
       shall be an error. The ''%%'' shall lose its special meaning when it is in
       a replacement string of more than one character or is preceded by a
       <backslash>.  For each <backslash> encountered in scanning _r_e_p_l_a_c_e_m_e_n_t
       from beginning to end, the following character shall lose its special
       meaning (if any). It is unspecified what special meaning is given to
       any character other than <backslash>, ''&&'', ''%%'', or digits.

       A line can be split by substituting a <newline> into it. The
       application shall ensure it escapes the <newline> in the _r_e_p_l_a_c_e_m_e_n_t by
       preceding it by <backslash>.  Such substitution cannot be done as part
       of a gg or vv _c_o_m_m_a_n_d _l_i_s_t.  The current line number shall be set to the
       address of the last line on which a substitution is performed. If no
       substitution is performed, the current line number shall be unchanged.
       If a line is split, a substitution shall be considered to have been
       performed on each of the new lines for the purpose of determining the
       new current line number. A substitution shall be considered to have
       been performed even if the replacement string is identical to the
       string that it replaces.

       The application shall ensure that the value of _f_l_a_g_s is zero or more
       of:

       _c_o_u_n_t   Substitute for the _c_o_u_n_tth occurrence only of the RE found on
               each addressed line.

       gg       Globally substitute for all non-overlapping instances of the RE
               rather than just the first one. If both gg and _c_o_u_n_t are
               specified, the results are unspecified.

       ll       Write to standard output the final line in which a substitution
               was made. The line shall be written in the format specified for
               the ll command.

       nn       Write to standard output the final line in which a substitution
               was made. The line shall be written in the format specified for
               the nn command.

       pp       Write to standard output the final line in which a substitution
               was made. The line shall be written in the format specified for
               the pp command.

   CCooppyy CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.,.)t_a_d_d_r_e_s_s

       The tt command shall be equivalent to the mm command, except that a copy
       of the addressed lines shall be placed after address _a_d_d_r_e_s_s (which can
       be 0); the current line number shall be set to the address of the last
       line added.

   UUnnddoo CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     u

       The uu command shall nullify the effect of the most recent command that
       modified anything in the buffer, namely the most recent aa, cc, dd, gg, ii,
       jj, mm, rr, ss, tt, uu, vv, GG, or VV command. All changes made to the buffer by
       a gg, GG, vv, or VV global command shall be undone as a single change; if
       no changes were made by the global command (such as with gg/RE/pp), the uu
       command shall have no effect. The current line number shall be set to
       the value it had immediately before the command being undone started.

   GGlloobbaall NNoonn--MMaattcchheedd CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (1,$)v/_R_E/_c_o_m_m_a_n_d _l_i_s_t

       This command shall be equivalent to the global command gg except that
       the lines that are marked during the first step shall be those for
       which the line excluding the terminating <newline> does not match the
       RE.

   IInntteerraaccttiivvee GGlloobbaall NNoott--MMaattcchheedd CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (1,$)V/_R_E/

       This command shall be equivalent to the interactive global command GG
       except that the lines that are marked during the first step shall be
       those for which the line excluding the terminating <newline> does not
       match the RE.

   WWrriittee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (1,$)w [[_f_i_l_e]]

       The ww command shall write the addressed lines into the file named by
       the pathname _f_i_l_e.  The command shall create the file, if it does not
       exist, or shall replace the contents of the existing file. The
       currently remembered pathname shall not be changed unless there is no
       remembered pathname.  If no pathname is given, the currently remembered
       pathname, if any, shall be used (see the ee and ff commands); the current
       line number shall be unchanged. If the command is successful, the
       number of bytes written shall be written to standard output, unless the
       --ss option was specified, in the following format:


           "%d\n", <_n_u_m_b_e_r _o_f _b_y_t_e_s _w_r_i_t_t_e_n>

       If _f_i_l_e begins with ''!!'', the rest of the line shall be taken to be a
       shell command line whose standard input shall be the addressed lines.
       Such a shell command line shall not be remembered as the current
       pathname. This usage of the write command with ''!!''  shall not be
       considered as a ``last ww command that wrote the entire buffer'', as
       described previously; thus, this alone shall not prevent the warning to
       the user if an attempt is made to destroy the editor buffer via the ee
       or qq commands.

   LLiinnee NNuummbbeerr CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     ($)=

       The line number of the addressed line shall be written to standard
       output in the following format:


           "%d\n", <_l_i_n_e _n_u_m_b_e_r>

       The current line number shall be unchanged by this command.

   SShheellll EEssccaappee CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     !_c_o_m_m_a_n_d

       The remainder of the line after the ''!!''  shall be sent to the command
       interpreter to be interpreted as a shell command line. Within the text
       of that shell command line, the unescaped character ''%%'' shall be
       replaced with the remembered pathname; if a ''!!''  appears as the first
       character of the command, it shall be replaced with the text of the
       previous shell command executed via ''!!''.  Thus, ""!!!!"" shall repeat the
       previous !_c_o_m_m_a_n_d. If any replacements of ''%%'' or ''!!''  are performed,
       the modified line shall be written to the standard output before
       _c_o_m_m_a_n_d is executed. The !!  command shall write:


           "!\n"

       to standard output upon completion, unless the --ss option is specified.
       The current line number shall be unchanged.

   NNuullll CCoommmmaanndd
       _S_y_n_o_p_s_i_s:

                     (.+1)

       An address alone on a line shall cause the addressed line to be
       written. A <newline> alone shall be equivalent to ""++11pp"".  The current
       line number shall be set to the address of the written line.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    Successful completion without any file or command errors.

       >0    An error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       When an error in the input script is encountered, or when an error is
       detected that is a consequence of the data (not) present in the file or
       due to an external condition such as a read or write error:

        *  If the standard input is a terminal device file, all input shall be
           flushed, and a new command read.

        *  If the standard input is a regular file, _e_d shall terminate with a
           non-zero exit status.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Because of the extremely terse nature of the default error messages,
       the prudent script writer begins the _e_d input commands with an HH
       command, so that if any errors do occur at least some clue as to the
       cause is made available.

       In earlier versions of this standard, an obsolescent -- option was
       described. This is no longer specified. Applications should use the --ss
       option. Using -- as a _f_i_l_e operand now produces unspecified results.
       This allows implementations to continue to support the former required
       behavior.

EEXXAAMMPPLLEESS
       None.

RRAATTIIOONNAALLEE
       The initial description of this utility was adapted from the SVID. It
       contains some features not found in Version 7 or BSD-derived systems.
       Some of the differences between the POSIX and BSD _e_d utilities include,
       but need not be limited to:

        *  The BSD -- option does not suppress the ''!!''  prompt after a !!
           command.

        *  BSD does not support the special meanings of the ''%%'' and ''!!''
           characters within a !!  command.

        *  BSD does not support the _a_d_d_r_e_s_s_e_s '';;'' and '',,''.

        *  BSD allows the command/suffix pairs pppp, llll, and so on, which are
           unspecified in this volume of POSIX.1-2017.

        *  BSD does not support the ''!!''  character part of the ee, rr, or ww
           commands.

        *  A failed gg command in BSD sets the line number to the last line
           searched if there are no matches.

        *  BSD does not default the _c_o_m_m_a_n_d _l_i_s_t to the pp command.

        *  BSD does not support the GG, hh, HH, nn, or VV commands.

        *  On BSD, if there is no inserted text, the insert command changes
           the current line to the referenced line -1; that is, the line
           before the specified line.

        *  On BSD, the _j_o_i_n command with only a single address changes the
           current line to that address.

        *  BSD does not support the PP command; moreover, in BSD it is
           synonymous with the pp command.

        *  BSD does not support the _u_n_d_o of the commands jj, mm, rr, ss, or tt.

        *  The Version 7 _e_d command WW, and the BSD _e_d commands WW, wwqq, and zz
           are not present in this volume of POSIX.1-2017.

       The --ss option was added to allow the functionality of the removed --
       option in a manner compatible with the Utility Syntax Guidelines.

       In early proposals there was a limit, {ED_FILE_MAX}, that described the
       historical limitations of some _e_d utilities in their handling of large
       files; some of these have had problems with files larger than 100000
       bytes. It was this limitation that prompted much of the desire to
       include a _s_p_l_i_t command in this volume of POSIX.1-2017. Since this
       limit was removed, this volume of POSIX.1-2017 requires that
       implementations document the file size limits imposed by _e_d in the
       conformance document. The limit {ED_LINE_MAX} was also removed;
       therefore, the global limit {LINE_MAX} is used for input and output
       lines.

       The manner in which the ll command writes non-printable characters was
       changed to avoid the historical backspace-overstrike method. On video
       display terminals, the overstrike is ambiguous because most terminals
       simply replace overstruck characters, making the ll format not useful
       for its intended purpose of unambiguously understanding the content of
       the line. The historical <backslash>-escapes were also ambiguous. (The
       string ""aa\\00001111"" could represent a line containing those six characters
       or a line containing the three characters ''aa'', a byte with a binary
       value of 1, and a 1.) In the format required here, a <backslash>
       appearing in the line is written as ""\\\\"" so that the output is truly
       unambiguous. The method of marking the ends of lines was adopted from
       the _e_x editor and is required for any line ending in <space>
       characters; the ''$$'' is placed on all lines so that a real ''$$'' at the
       end of a line cannot be misinterpreted.

       Earlier versions of this standard allowed for implementations with
       bytes other than eight bits, but this has been modified in this
       version.

       The description of how a NUL is written was removed. The NUL character
       cannot be in text files, and this volume of POSIX.1-2017 should not
       dictate behavior in the case of undefined, erroneous input.

       Unlike some of the other editing utilities, the filenames accepted by
       the EE, ee, RR, and rr commands are not patterns.

       Early proposals stated that the --pp option worked only when standard
       input was associated with a terminal device. This has been changed to
       conform to historical implementations, thereby allowing applications to
       interpose themselves between a user and the _e_d utility.

       The form of the substitute command that uses the nn suffix was limited
       in some historical documentation (where this was described incorrectly
       as ``backreferencing''). This limit has been omitted because there is
       no reason why an editor processing lines of {LINE_MAX} length should
       have this restriction. The command ss//xx//XX//22004477 should be able to
       substitute the 2047th occurrence of ''xx'' on a line.

       The use of printing commands with printing suffixes (such as ppnn, llpp,
       and so on) was made unspecified because BSD-based systems allow this,
       whereas System V does not.

       Some BSD-based systems exit immediately upon receipt of end-of-file if
       all of the lines in the file have been deleted. Since this volume of
       POSIX.1-2017 refers to the qq command in this instance, such behavior is
       not allowed.

       Some historical implementations returned exit status zero even if
       command errors had occurred; this is not allowed by this volume of
       POSIX.1-2017.

       Some historical implementations contained a bug that allowed a single
       <period> to be entered in input mode as <backslash> <period> <newline>.
       This is not allowed by _e_d because there is no description of escaping
       any of the characters in input mode; <backslash> characters are entered
       into the buffer exactly as typed. The typical method of entering a
       single <period> has been to precede it with another character and then
       use the substitute command to delete that character.

       It is difficult under some modes of some versions of historical
       operating system terminal drivers to distinguish between an end-of-file
       condition and terminal disconnect. POSIX.1-2008 does not require
       implementations to distinguish between the two situations, which
       permits historical implementations of the _e_d utility on historical
       platforms to conform. Implementations are encouraged to distinguish
       between the two, if possible, and take appropriate action on terminal
       disconnect.

       Historically, _e_d accepted a zero address for the aa and rr commands in
       order to insert text at the start of the edit buffer. When the buffer
       was empty the command ..== returned zero. POSIX.1-2008 requires
       conformance to historical practice.

       For consistency with the aa and rr commands and better user
       functionality, the ii and cc commands must also accept an address of 0,
       in which case 0_i is treated as 1_i and likewise for the cc command.

       All of the following are valid addresses:

       +++         Three lines after the current line.

       /_p_a_t_t_e_r_n/-  One line before the next occurrence of pattern.

       -2          Two lines before the current line.

       3 ---- 2    Line one (note the intermediate negative address).

       1 2 3       Line six.

       Any number of addresses can be provided to commands taking addresses;
       for example, ""11,,22,,33,,44,,55pp"" prints lines 4 and 5, because two is the
       greatest valid number of addresses accepted by the pprriinntt command. This,
       in combination with the <semicolon> delimiter, permits users to create
       commands based on ordered patterns in the file. For example, the
       command ""33;;//ffoooo//;;++22pp"" will display the first line after line 3 that
       contains the pattern _f_o_o, plus the next two lines. Note that the
       address ""33;;"" must still be evaluated before being discarded, because
       the search origin for the ""//ffoooo//"" command depends on this.

       Historically, _e_d disallowed address chains, as discussed above,
       consisting solely of <comma> or <semicolon> separators; for example,
       "",,,,,,"" or "";;;;;;"" were considered an error. For consistency of address
       specification, this restriction is removed. The following table lists
       some of the address forms now possible:

           +--------+-------+-------+------------+-----------------------+
           |AAddddrreessss | AAddddrr11 | AAddddrr22 |   SSttaattuuss   |        CCoommmmeenntt        |
           +--------+-------+-------+------------+-----------------------+
           |7,      |   7   |   7   | Historical |                       |
           |7,5,    |   5   |   5   | Historical |                       |
           |7,5,9   |   5   |   9   | Historical |                       |
           |7,9     |   7   |   9   | Historical |                       |
           |7,+     |   7   |   8   | Historical |                       |
           |,       |   1   |   $   | Historical |                       |
           |,7      |   1   |   7   | Extension  |                       |
           |,,      |   $   |   $   | Extension  |                       |
           |,;      |   $   |   $   | Extension  |                       |
           |7;      |   7   |   7   | Historical |                       |
           |7;5;    |   5   |   5   | Historical |                       |
           |7;5;9   |   5   |   9   | Historical |                       |
           |7;5,9   |   5   |   9   | Historical |                       |
           |7;$;4   |   $   |   4   | Historical | Valid, but erroneous. |
           |7;9     |   7   |   9   | Historical |                       |
           |7;+     |   7   |   8   | Historical |                       |
           |;       |   .   |   $   | Historical |                       |
           |;7      |   .   |   7   | Extension  |                       |
           |;;      |   $   |   $   | Extension  |                       |
           |;,      |   $   |   $   | Extension  |                       |
           +--------+-------+-------+------------+-----------------------+
       Historically, _e_d accepted the ''^^'' character as an address, in which
       case it was identical to the <hyphen-minus> character. POSIX.1-2008
       does not require or prohibit this behavior.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _1_._4, _U_t_i_l_i_t_y _D_e_s_c_r_i_p_t_i_o_n _D_e_f_a_u_l_t_s, _e_x, _s_e_d, _s_h, _v_i

       The Base Definitions volume of POSIX.1-2017, _T_a_b_l_e _5_-_1, _E_s_c_a_p_e
       _S_e_q_u_e_n_c_e_s _a_n_d _A_s_s_o_c_i_a_t_e_d _A_c_t_i_o_n_s, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s,
       _S_e_c_t_i_o_n _9_._3, _B_a_s_i_c _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s, _C_h_a_p_t_e_r _1_1, _G_e_n_e_r_a_l _T_e_r_m_i_n_a_l
       _I_n_t_e_r_f_a_c_e, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                                ED(1)
