1 ED(1)                            User Commands                           ED(1)
   2 
   3 
   4 
   5 NAME
   6        ed, red - text editor
   7 
   8 SYNOPSIS
   9        /usr/bin/ed [-s | -] [-p string] [-x] [-C] [file]
  10 
  11 
  12        /usr/xpg4/bin/ed [-s | -] [-p string] [-x] [-C] [file]
  13 
  14 
  15        /usr/xpg6/bin/ed [-s | -] [-p string] [-x] [-C] [file]
  16 
  17 
  18        /usr/bin/red [-s | -] [-p string] [-x] [-C] [file]
  19 
  20 
  21 DESCRIPTION
  22        The ed utility is the standard text editor. If file is specified, ed
  23        simulates an e command (see below) on the named file. That is, the file
  24        is read into ed's buffer so that it can be edited.
  25 
  26 
  27        The ed utility operates on a copy of the file it is editing. Changes
  28        made to the copy have no effect on the file until a w (write) command
  29        is given. The copy of the text being edited resides in a temporary file
  30        called the buffer. There is only one buffer.
  31 
  32 
  33        The red utility is a restricted version of ed. It will only allow
  34        editing of files in the current directory. red prohibits executing
  35        shell commands via !shell command. Attempts to bypass these
  36        restrictions result in an error message (restricted shell).
  37 
  38 
  39        Both ed and red support the fspec(4) formatting capability.  The
  40        default terminal mode is either stty -tabs or stty tab3, where tab stops
  41        are set at eight columns (see stty(1)). If, however, the first line of
  42        file contains a format specification, that specification will override
  43        the default mode. For example, tab stops would be set at 5, 10, and 15,
  44        and a maximum line length of 72 would be imposed if the first line of
  45        file contains
  46 
  47          <:t5,10,15 s72:>
  48 
  49 
  50 
  51 
  52        Commands to ed have a simple and regular structure: zero, one, or two
  53        addresses followed by a single-character command, possibly followed by
  54        parameters to that command. These addresses specify one or more lines
  55        in the buffer. Every command that requires addresses has default
  56        addresses, so that the addresses can very often be omitted.
  57 
  58 
  59        In general, only one command may appear on a line. Certain commands
  60        allow the input of text. This text is placed in the appropriate place
  61        in the buffer.  While ed is accepting text, it is said to be in input
  62        mode. In this mode, no commands are recognized; all input is merely
  63        collected. Leave input mode by typing a period (.) at the beginning of
  64        a line, followed immediately by a carriage return.
  65 
  66 
  67        If ed executes commands with arguments, it uses the default shell
  68        /usr/bin/sh (see sh(1)).
  69 
  70    Regular Expressions
  71        The ed utility supports a limited form of regular expression notation.
  72        Regular expressions are used in addresses to specify lines and in some
  73        commands (for example, s) to specify portions of a line that are to be
  74        substituted. To understand addressing in ed, it is necessary to know
  75        that at any time there is a current line. Generally speaking, the
  76        current line is the last line affected by a command. The exact effect
  77        on the current line is discussed under the description of each command.
  78 
  79 
  80        Internationalized Basic Regular Expressions are used for all system-
  81        supplied locales. See regex(5).
  82 
  83    ed Commands
  84        Commands may require zero, one, or two addresses. Commands that require
  85        no addresses regard the presence of an address as an error. Commands
  86        that accept one or two addresses assume default addresses when an
  87        insufficient number of addresses is given; if more addresses are given
  88        than such a command requires, the last one(s) are used.
  89 
  90 
  91        Typically, addresses are separated from each other by a comma (,). They
  92        may also be separated by a semicolon (;). In the latter case, the first
  93        address is calculated, the current line (.) is set to that value, and
  94        then the second address is calculated. This feature can be used to
  95        determine the starting line for forward and backward searches (see
  96        Rules 5 and 6, above).  The second address of any two-address sequence
  97        must correspond to a line in the buffer that follows the line
  98        corresponding to the first address.
  99 
 100 
 101        For /usr/xpg6/gbin/ed, the address can be omitted on either side of the
 102        comma or semicolon separator, in which case the resulting address pairs
 103        are as follows:
 104 
 105 
 106 
 107 
 108        +----------+-------------+
 109        |Specified |  Resulting  |
 110        +----------+-------------+
 111        |,         | 1 , $       |
 112        +----------+-------------+
 113        |, addr    | 1 , addr    |
 114        +----------+-------------+
 115        |addr ,    | addr , addr |
 116        +----------+-------------+
 117        |;         | 1 ; $       |
 118        +----------+-------------+
 119        |; addr    | 1 ; addr    |
 120        +----------+-------------+
 121        |addr ;    | addr ; addr |
 122        +----------+-------------+
 123 
 124 
 125        Any <blank>s included between addresses,   address separators, or address
 126        offsets are ignored.
 127 
 128 
 129        In the following list of ed commands, the parentheses shown prior to
 130        the command are not part of the address. Rather, the parentheses show
 131        the default address(es) for the command.
 132 
 133 
 134        Each address component can be preceded by zero or more blank
 135        characters. The command letter can be preceded by zero or more blank
 136        characters. If a suffix letter (l, n, or p) is given, it must
 137        immediately follow the command.
 138 
 139 
 140        The e, E, f, r, and w commands take an optional file parameter,
 141        separated from the command letter by one or more blank characters.
 142 
 143 
 144        If changes have been made in the buffer since the last w command that
 145        wrote the entire buffer, ed warns the user if an attempt is made to
 146        destroy the editor buffer via the e or q commands. The ed utility
 147        writes the string:
 148 
 149          "?\n"
 150 
 151 
 152 
 153 
 154        (followed by an explanatory message if help mode has been enabled via
 155        the H command) to standard output and continues in command mode with
 156        the current line number unchanged. If the e or q command is repeated
 157        with no intervening command, ed takes effect.
 158 
 159 
 160        If an end-of-file is detected on standard input when a command is
 161        expected, the ed utility acts as if a q command had been entered.
 162 
 163 
 164        It is generally illegal for more than one command to appear on a line.
 165        However, any command (except e, f, r, or w) may be suffixed by l, n, or
 166        p in which case the current line is either listed, numbered or written,
 167        respectively, as discussed below under the l, n, and p commands.
 168 
 169        (.)a
 170        <text>
 171        .
 172                   The append command accepts zero or more lines of text and
 173                   appends it after the addressed line in the buffer. The
 174                   current line (.) is left at the last inserted line, or, if
 175                   there were none, at the addressed line. Address 0 is legal
 176                   for this command: it causes the ``appended'' text to be
 177                   placed at the beginning of the buffer. The maximum number of
 178                   characters that may be entered from a terminal is 256 per
 179                   line (including the new-line character).
 180 
 181 
 182        (.,.)c
 183        <text>
 184        .
 185                   The change command deletes the addressed lines from the
 186                   buffer, then accepts zero or more lines of text that
 187                   replaces these lines in the buffer. The current line (.) is
 188                   left at the last line input, or, if there were none, at the
 189                   first line that was not deleted. If the lines deleted were
 190                   originally at the end of the buffer, the current line number
 191                   will be set to the address of the new last line. If no lines
 192                   remain in the buffer, the current line number will be set to
 193                   0.
 194 
 195                   /usr/xpg4/bin/ed
 196                                       Address 0 is not legal for this command.
 197 
 198 
 199                   /usr/xpg6/bin/ed
 200                                       Address 0 is valid for this command. It
 201                                       is interpreted as if the address 1 were
 202                                       specified.
 203 
 204 
 205 
 206        C
 207                   Same as the X command, described later, except that ed
 208                   assumes all text read in for the e and r commands is
 209                   encrypted unless a null key is typed in.
 210 
 211 
 212        (.,.)d
 213                   The delete command deletes the addressed lines from the
 214                   buffer. The line after the last line deleted becomes the
 215                   current line. If the lines deleted were originally at the
 216                   end of the buffer, the new last line becomes the current
 217                   line. If no lines remain in the buffer, the current line
 218                   number will be set to 0.
 219 
 220 
 221        e file
 222                   The edit command deletes the entire contents of the buffer
 223                   and then reads the contents of file into the buffer. The
 224                   current line (.) is set to the last line of the buffer. If
 225                   file is not given, the currently remembered file name, if
 226                   any, is used (see the f command). The number of bytes read
 227                   will be written to standard output, unless the -s option was
 228                   specified, in the following format:
 229 
 230                   "%d\n" <number of bytes read>
 231 
 232                   file is remembered for possible use as a default file name
 233                   in subsequent e, E, r, and w commands. If file is replaced
 234                   by !, the rest of the line is taken to be a shell ( sh(1))
 235                   command whose output is to be read. Such a shell command is
 236                   not remembered as the current file name.  See also
 237                   DIAGNOSTICS below. All marks are discarded upon the
 238                   completion of a successful e command. If the buffer has
 239                   changed since the last time the entire buffer was written,
 240                   the user is warned, as described previously.
 241 
 242 
 243        E file
 244                   The Edit command is like e, except that the editor does not
 245                   check to see if any changes have been made to the buffer
 246                   since the last w command.
 247 
 248 
 249        f file
 250                   If file is given, the f command changes the currently
 251                   remembered path name to file. Whether the name is changed or
 252                   not, the f command then writes the (possibly new) currently
 253                   remembered path name to the standard output in the following
 254                   format:
 255 
 256                   "%s\n"pathname
 257 
 258                   The current line number is unchanged.
 259 
 260 
 261        (1,$)g/RE/command list
 262                                  In the global command, the first step is to
 263                                  mark every line that matches the given RE.
 264                                  Then, for every such line, the given command
 265                                  list is executed with the current line (.)
 266                                  initially set to that line. When the g
 267                                  command completes, the current line number
 268                                  has the value assigned by the last command in
 269                                  the command list. If there were no matching
 270                                  lines, the current line number is not
 271                                  changed. A single command or the first of a
 272                                  list of commands appears on the same line as
 273                                  the global command. All lines of a multi-line
 274                                  list except the last line must be ended with
 275                                  a backslash (\); a, i, and c commands and
 276                                  associated input are permitted. The .
 277                                  terminating input mode may be omitted if it
 278                                  would be the last line of the command list.
 279                                  An empty command list is equivalent to the p
 280                                  command. The g, G, v, V, and ! commands are
 281                                  not permitted in the command list. See also
 282                                  the NOTES and the last paragraph before FILES
 283                                  below. Any character other than space or
 284                                  newline can be used instead of a slash to
 285                                  delimit the RE. Within the RE, the RE
 286                                  delimiter itself can be used as a literal
 287                                  character if it is preceded by a backslash.
 288 
 289 
 290        (1,$)G/RE/
 291                                  In the interactive Global command, the first
 292                                  step is to mark every line that matches the
 293                                  given RE. Then, for every such line, that
 294                                  line is written to standard output, the
 295                                  current line (.) is changed to that line, and
 296                                  any one command (other than one of the a, c,
 297                                  i, g, G, v, and V commands) may be input and
 298                                  is executed. After the execution of that
 299                                  command, the next marked line is written, and
 300                                  so on. A new-line acts as a null command. An &
 301                                  causes the re-execution of the most recent
 302                                  non-null command executed within the current
 303                                  invocation of G. Note:  The commands input as
 304                                  part of the execution of the G command may
 305                                  address and affect any lines in the buffer.
 306                                  The final value of the current line number is
 307                                  the value set by the last command
 308                                  successfully executed. (Notice that the last
 309                                  command successfully executed is the G
 310                                  command itself if a command fails or the null
 311                                  command is specified.) If there were no
 312                                  matching lines, the current line number is
 313                                  not changed. The G command can be terminated
 314                                  by a SIGINT signal. The G command can be
 315                                  terminated by an interrupt signal (ASCII DEL
 316                                  or BREAK).  Any character other than space or
 317                                  newline can be used instead of a slash to
 318                                  delimit the RE. Within the RE, the RE
 319                                  delimiter itself can be used as a literal
 320                                  character if it is preceded by a backslash.
 321 
 322 
 323        h
 324                                  The help command gives a short error message
 325                                  that explains the reason for the most recent
 326                                  ? diagnostic. The current line number is
 327                                  unchanged.
 328 
 329 
 330        H
 331                                  The Help command causes ed to enter a mode in
 332                                  which error messages are written for all
 333                                  subsequent ? diagnostics. It also explains
 334                                  the previous ? if there was one. The H
 335                                  command alternately turns this mode on and
 336                                  off; it is initially off. The current line
 337                                  number is unchanged.
 338 
 339 
 340        (.,.)i
 341        <text>
 342        .
 343                                  The insert command accepts zero or more lines
 344                                  of text and inserts it before the addressed
 345                                  line in the buffer. The current line (.) is
 346                                  left at the last inserted line, or, if there
 347                                  were none, at the addressed line. This
 348                                  command differs from the a command only in
 349                                  the placement of the input text. The maximum
 350                                  number of characters that may be entered from
 351                                  a terminal is 256 per line (including the
 352                                  new-line character).
 353 
 354                                  /usr/xpg4/bin/ed
 355                                                      Address 0 is not legal
 356                                                      for this command.
 357 
 358 
 359                                  /usr/xpg6/bin/ed
 360                                                      Address 0 is valid for
 361                                                      this command. It is
 362                                                      interpreted as if the
 363                                                      address 1 were specified.
 364 
 365 
 366 
 367        (.,.+1)j
 368                                  The join command joins contiguous lines by
 369                                  removing the appropriate new-line characters.
 370                                  If exactly one address is given, this command
 371                                  does nothing. If lines are joined, the
 372                                  current line number is set to the address of
 373                                  the joined line. Otherwise, the current line
 374                                  number is unchanged.
 375 
 376 
 377        (.)kx
 378                                  The mark command marks the addressed line
 379                                  with name x, which must be an ASCII lower-case
 380                                  letter (a-z). The address  ax then addresses
 381                                  this line. The current line (.) is unchanged.
 382 
 383 
 384        (.,.)l
 385                                  The l command writes to standard output the
 386                                  addressed lines in a visually unambiguous
 387                                  form. The characters ( \\, \a, \b, \f, \r,
 388                                  \t, \v) are written as the corresponding
 389                                  escape sequence. The \n in that table is not
 390                                  applicable. Non-printable characters not in
 391                                  the table are written as one three-digit octal
 392                                  number (with a preceding backslash character)
 393                                  for each byte in the character, with the most
 394                                  significant byte first.
 395 
 396                                  Long lines are folded, with the point of
 397                                  folding indicated by writing
 398                                  backslash/newline character. The length at
 399                                  which folding occurs is unspecified, but
 400                                  should be appropriate for the output device.
 401                                  The end of each line is marked with a $. When
 402                                  using the /usr/xpg6/bin/ed command, the end
 403                                  of each line is marked with a $ due to
 404                                  folding, and $ characters within the text are
 405                                  written with a preceding backslash. An l
 406                                  command can be appended to any other command
 407                                  other than e, E, f, q, Q, r, w, or !. The
 408                                  current line number is set to the address of
 409                                  the last line written.
 410 
 411 
 412        (.,.)ma
 413                                  The move command repositions the addressed
 414                                  line(s) after the line addressed by a.
 415                                  Address 0 is legal for a and causes the
 416                                  addressed line(s) to be moved to the
 417                                  beginning of the file. It is an error if
 418                                  address a falls within the range of moved
 419                                  lines. The current line (.) is left at the
 420                                  last line moved.
 421 
 422 
 423        (.,.)n
 424                                  The number command writes the addressed
 425                                  lines, preceding each line by its line number
 426                                  and a tab character. The current line (.) is
 427                                  left at the last line written. The n command
 428                                  may be appended to any command other than e,
 429                                  E, f, q, Q, r, w, or !.
 430 
 431 
 432        (.,.)p
 433                                  The print command writes the addressed lines
 434                                  to standard output. The current line (.) is
 435                                  left at the last line written. The p command
 436                                  may be appended to any command other than e,
 437                                  E, f, q, Q, r, w, or !. For example, dp
 438                                  deletes the current line and writes the new
 439                                  current line.
 440 
 441 
 442        P
 443                                  The P command causes ed to prompt with an
 444                                  asterisk (*) (or string, if -p is specified)
 445                                  for all subsequent commands. The P command
 446                                  alternatively turns this mode on and off; it
 447                                  is initially on if the -p option is specified,
 448                                  otherwise off. The current line is unchanged.
 449 
 450 
 451        q
 452                                  The quit command causes ed to exit. If the
 453                                  buffer has changed since the last time the
 454                                  entire buffer was written, the user is
 455                                  warned. See DIAGNOSTICS.
 456 
 457 
 458        Q
 459                                  The editor exits without checking if changes
 460                                  have been made in the buffer since the last w
 461                                  command.
 462 
 463 
 464        ($)r file
 465                                  The read command reads the contents of file
 466                                  into the buffer. If file is not given, the
 467                                  currently remembered file name, if any, is
 468                                  used (see the e and f commands). The
 469                                  currently remembered file name is not changed
 470                                  unless file is the very first file name
 471                                  mentioned since ed was invoked. Address 0 is
 472                                  legal for r and causes the file to be read in
 473                                  at the beginning of the buffer. If the read
 474                                  is successful and the -s option was not
 475                                  specified, the number of characters read is
 476                                  written to standard output in the following
 477                                  format:
 478 
 479                                    %d\n, <number of bytes read>
 480 
 481 
 482                                  The current line (.) is set to the last line
 483                                  read. If file is replaced by !, the rest of
 484                                  the line is taken to be a shell command (see
 485                                  sh(1)) whose output is to be read. For
 486                                  example, $r !ls appends the current directory
 487                                  to the end of the file being edited. Such a
 488                                  shell command is not remembered as the
 489                                  current file name.
 490 
 491 
 492        (.,.)s/RE/replacement/
 493        (.,.)s/RE/replacement/count, count=[1-2047]
 494        (.,.)s/RE/replacement/g
 495        (.,.)s/RE/replacement/l
 496        (.,.)s/RE/replacement/n
 497        (.,.)s/RE/replacement/p
 498            The substitute command searches each addressed line for an
 499            occurrence of the specified RE. Zero or more substitution commands
 500            can be specified. In each line in which a match is found, all (non-
 501            overlapped) matched strings are replaced by the replacement if the
 502            global replacement indicator g appears after the command. If the
 503            global indicator does not appear, only the first occurrence of the
 504            matched string is replaced. If a number count appears after the
 505            command, only the count-th occurrence of the matched string on each
 506            addressed line is replaced. It is an error if the substitution
 507            fails on all addressed lines. Any character other than space or
 508            new-line may be used instead of the slash (/) to delimit the RE and
 509            the replacement. The current line (.) is left at the last line on
 510            which a substitution occurred. Within the RE, the RE delimiter
 511            itself can be used as a literal character if it is preceded by a
 512            backslash. See also the last paragraph before FILES below.
 513 
 514            An ampersand (&) appearing in the replacement is replaced by     the
 515            string matching the RE on the current line. The special meaning of
 516            & in     this context may be suppressed by preceding it by \. As a more
 517            general feature, the characters \n, where n is a digit, are
 518            replaced by the text matched by the n-th regular subexpression of
 519            the specified RE enclosed between \( and \). When nested
 520            parenthesized subexpressions are present, n is determined by
 521            counting occurrences of \( starting from the left. When the
 522            character % is the only character in the replacement, the
 523            replacement used in the most recent substitute command is used as
 524            the replacement in the current substitute command. If there was no
 525            previous substitute command, the use of % in this manner is an
 526            error. The % loses its special meaning when it is in a replacement
 527            string of more than one character or is preceded by a \. For each
 528            backslash (\) encountered in scanning replacement from beginning to
 529            end, the following character loses its special meaning (if any). It
 530            is unspecified what special meaning is given to any character other
 531            than &, \, %, or digits.
 532 
 533            A line may be split by substituting a new-line character into it.
 534            The new-line in the replacement must be escaped by preceding it by
 535            \. Such substitution cannot be done as part of a g or v command
 536            list. The current line number is set to the address of the last
 537            line on which a substitution is performed. If no substitution is
 538            performed, the current line number is unchanged. If a line is
 539            split, a substitution is considered to have been performed on each
 540            of the new lines for the purpose of determining the new current
 541            line number. A substitution is considered to have been performed
 542            even if the replacement string is identical to the string that it
 543            replaces.
 544 
 545            The substitute command supports the following indicators:
 546 
 547            count
 548                     Substitute for the countth occurrence only of the RE found
 549                     on each addressed line. count must be between 1-2047.
 550 
 551 
 552            g
 553                     Globally substitute for all non-overlapping instances of
 554                     the RE rather than just the first one. If both g and count
 555                     are specified, the results are unspecified.
 556 
 557 
 558            l
 559                     Write to standard output the final line in which a
 560                     substitution was made. The line is written in the format
 561                     specified for the l command.
 562 
 563 
 564            n
 565                     Write to standard output the final line in which a
 566                     substitution was made. The line is written in the format
 567                     specified for the n command.
 568 
 569 
 570            p
 571                     Write to standard output the final line in which a
 572                     substitution was made. The line will be written in the
 573                     format specified for the p command.
 574 
 575 
 576 
 577        (.,.)ta
 578            This command acts just like the m command, except that a copy of
 579            the addressed lines is placed after address a (which may be 0). The
 580            current line (.) is left at the last line copied.
 581 
 582 
 583        u
 584            The undo command nullifies the effect of the most recent command
 585            that modified anything in the buffer, namely the most recent a, c,
 586            d, g, i, j, m, r, s, t, u, v, G, or V command. All changes made to
 587            the buffer by a g, G, v, or V global command is undone as a single
 588            change.If no changes were made by the global command (such as with
 589            g/ RE/p), the u command has no effect. The current line number is
 590            set to the value it had  immediately before the  command being
 591            undone started.
 592 
 593 
 594        (1,$)v/RE/command list
 595            This command is the same as the global command g, except that the
 596            lines marked during the first step are those that do not match the
 597            RE.
 598 
 599 
 600        (1,$)V/RE/
 601            This command is the same as the interactive global command G,
 602            except that the lines that are marked during the first step are
 603            those that do not match the RE.
 604 
 605 
 606        (1,$)w file
 607            The write command writes the addressed lines into file. If file
 608            does not exist, it is created with mode 666 (readable and writable
 609            by everyone), unless your file creation mask dictates otherwise.
 610            See the description of the umask special command on sh(1). The
 611            currently remembered file name is not changed unless file is the
 612            very first file name mentioned since ed was invoked. If no file
 613            name is given, the currently remembered file name, if any, is used
 614            (see the e and f commands). The current line (.) is unchanged. If
 615            the command is successful, the number of characters written is
 616            printed, unless the -s option is specified in the following format:
 617 
 618              "%d\n",<number of bytes written>
 619 
 620 
 621            If file is replaced by !, the rest of the line is taken to be a
 622            shell (see sh(1)) command whose standard input is the addressed
 623            lines.  Such a shell command is not remembered as the current path
 624            name. This usage of the write command with ! is to be considered as
 625            a ``last w command that wrote the entire buffer''.
 626 
 627 
 628        (1,$)W file
 629                           This command is the same as the write command above,
 630                           except that it appends the addressed lines to the
 631                           end of file if it exists. If file does not exist, it
 632                           is created as described above for the w command.
 633 
 634 
 635        X
 636                           An educated guess is made to determine whether text
 637                           read for the e and r commands is encrypted. A null
 638                           key turns off encryption. Subsequent e, r, and w
 639                           commands will use this key to encrypt or decrypt the
 640                           text. An explicitly empty key turns off encryption.
 641                           Also, see the -x option of ed.
 642 
 643 
 644        ($)=
 645                           The line number of the addressed line is written to
 646                           standard output in the following format:
 647 
 648                             "%d\n"<line      number>
 649 
 650 
 651                           The current line number is unchanged by this
 652                           command.
 653 
 654 
 655        !shell command
 656                           The remainder of the line after the ! is sent to the
 657                           UNIX system shell (see sh(1)) to be interpreted as a
 658                           command. Within the text of that command, the
 659                           unescaped character % is replaced with the
 660                           remembered file name. If a ! appears as the first
 661                           character of the shell command, it is replaced with
 662                           the text of the previous shell command. Thus, !!
 663                           repeats the last shell command. If any replacements
 664                           of % or ! are performed, the modified line is
 665                           written to the standard output before command is
 666                           executed. The ! command will write:
 667 
 668                           "!\n"
 669 
 670                           to standard output upon completion, unless the -s
 671                           option is specified.  The current line number is
 672                           unchanged.
 673 
 674 
 675        (.+1)<new-line>
 676                           An address alone on a line causes the addressed line
 677                           to be written. A new-line alone is equivalent to
 678                           .+1p. It is useful for stepping forward through the
 679                           buffer. The current line number will be set to the
 680                           address of the written line.
 681 
 682 
 683 
 684        If an interrupt signal (ASCII DEL or BREAK) is sent, ed writes a "?\n"
 685        and returns to its command level.
 686 
 687 
 688        The ed utility takes the standard action for all signals with the
 689        following exceptions:
 690 
 691        SIGINT
 692                  The ed utility interrupts its current activity, writes the
 693                  string "?\n" to standard output, and returns to command mode.
 694 
 695 
 696        SIGHUP
 697                  If the buffer is not empty and has changed since the last
 698                  write, the ed utility attempts to write a copy of the buffer
 699                  in a file. First, the file named ed.hup in the current
 700                  directory is used. If that fails, the file named ed.hup in
 701                  the directory named by the HOME environment variable is used.
 702                  In any case, the ed utility exits without returning to
 703                  command mode.
 704 
 705 
 706 
 707        Some size limitations are in effect: 512 characters in a line, 256
 708        characters in a global command list, and 255 characters in the path
 709        name of a file (counting slashes). The limit on the number of lines
 710        depends on the amount of user memory. Each line takes 1 word.
 711 
 712 
 713        When reading a file, ed discards ASCII and NUL characters.
 714 
 715 
 716        If a file is not terminated by a new-line character, ed adds one and
 717        puts out a message explaining what it did.
 718 
 719 
 720        If the closing delimiter of an RE or of a replacement string (for
 721        example, /) would be the last character before a new-line, that
 722        delimiter may be omitted, in which case the addressed line is written.
 723        The following pairs of commands are equivalent:
 724 
 725        s/s1/s2
 726                   s/s1/s2/p
 727 
 728 
 729        g/s1
 730                   g/s1/p
 731 
 732 
 733        ?s1
 734                   ?s1?
 735 
 736 
 737 
 738        If an invalid command is entered, ed writes the string:
 739 
 740 
 741        "?\n"
 742 
 743 
 744        (followed by an explanatory message if help mode has been enabled by
 745        the H command) to standard output and continues in command mode with
 746        the current line number unchanged.
 747 
 748 OPTIONS
 749        -C
 750                     Encryption option. The same as the -x option, except that
 751                     ed simulates a C command. The C command is like the X
 752                     command, except that all text read in is assumed to have
 753                     been encrypted.
 754 
 755 
 756        -pstring
 757                     Allows the user to specify a prompt string. By default,
 758                     there is no prompt string.
 759 
 760 
 761        -s |  -;
 762                     Suppresses the writing of character counts by e, r, and w
 763                     commands, of diagnostics from e and q commands, and of the
 764                     ! prompt after a !shell command.
 765 
 766 
 767        -x
 768                     Encryption option. When -x is used, ed simulates an X
 769                     command and prompts the user for a key. The X command
 770                     makes an educated guess to determine whether text read in
 771                     is encrypted or not. The temporary buffer file is
 772                     encrypted also, using a transformed version of the key
 773                     typed in for the -x option. See NOTES.
 774 
 775 
 776 OPERANDS
 777        The following operand is supported:
 778 
 779        file
 780                If file is specified, ed simulates an e command on the file
 781                named by the path name file before accepting commands from the
 782                standard input.
 783 
 784 
 785 USAGE
 786        See largefile(5) for the description of the behavior of ed and red when
 787        encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
 788 
 789 ENVIRONMENT VARIABLES
 790        See environ(5) for descriptions of the following environment variables
 791        that affect the execution of ed: HOME, LANG, LC_ALL, LC_CTYPE,
 792        LC_COLLATE, LC_MESSAGES, and NLSPATH.
 793 
 794 EXIT STATUS
 795        The following exit values are returned:
 796 
 797        0
 798              Successful completion without any file or command errors.
 799 
 800 
 801        >0
 802              An error occurred.
 803 
 804 
 805 FILES
 806        $TMPDIR
 807                    If this environment variable is not NULL, its value is used
 808                    in place of /var/tmp as the directory name for the
 809                    temporary work file.
 810 
 811 
 812        /var/tmp
 813                    If /var/tmp exists, it is used as the directory name for
 814                    the temporary work file.
 815 
 816 
 817        /tmp
 818                    If the environment variable TMPDIR does not exist or is
 819                    NULL, and if /var/tmp does not exist, then /tmp is used as
 820                    the directory name for the temporary work file.
 821 
 822 
 823        ed.hup
 824                    Work is saved here if the terminal is hung up.
 825 
 826 
 827 ATTRIBUTES
 828        See attributes(5) for descriptions of the following attributes:
 829 
 830    /usr/bin/ed, /usr/bin/red
 831 
 832        +---------------+-----------------+
 833        |ATTRIBUTE TYPE | ATTRIBUTE VALUE |
 834        +---------------+-----------------+
 835        |CSI            | Enabled         |
 836        +---------------+-----------------+
 837 
 838    /usr/xpg4/bin/ed
 839 
 840        +--------------------+-----------------+
 841        |  ATTRIBUTE TYPE    | ATTRIBUTE VALUE |
 842        +--------------------+-----------------+
 843        |CSI                 | Enabled         |
 844        +--------------------+-----------------+
 845        |Interface Stability | Standard        |
 846        +--------------------+-----------------+
 847 
 848    /usr/xpg6/bin/ed
 849 
 850        +--------------------+-----------------+
 851        |  ATTRIBUTE TYPE    | ATTRIBUTE VALUE |
 852        +--------------------+-----------------+
 853        |CSI                 | Enabled         |
 854        +--------------------+-----------------+
 855        |Interface Stability | Standard        |
 856        +--------------------+-----------------+
 857 
 858 SEE ALSO
 859        edit(1), ex(1), grep(1), ksh(1), sed(1), sh(1), stty(1), umask(1),
 860        vi(1), fspec(4), attributes(5), environ(5), largefile(5), regex(5),
 861        standards(5)
 862 
 863 DIAGNOSTICS
 864        ?
 865                 for command errors.
 866 
 867 
 868        ?file
 869                 for an inaccessible file. Use the help and Help commands for
 870                 detailed explanations.
 871 
 872 
 873 
 874        If changes have been made in the buffer since the last w command that
 875        wrote the entire buffer, ed warns the user if an attempt is made to
 876        destroy ed's buffer via the e or q commands. It writes ? and allows one
 877        to continue editing. A second e or q command at this point will take
 878        effect. The -s command-line option inhibits this feature.
 879 
 880 NOTES
 881        The - option, although it continues to be supported, has been replaced
 882        in the documentation by the -s option that follows the Command Syntax
 883        Standard (see Intro(1)).
 884 
 885 
 886        A ! command cannot be subject to a g or a v command.
 887 
 888 
 889        The ! command and the ! escape from the e, r, and w commands cannot be
 890        used if the editor is invoked from a restricted shell (see sh(1)).
 891 
 892 
 893        The sequence \n in an RE does not match a new-line character.
 894 
 895 
 896        If the editor input is coming from a command file (for example, ed file
 897        < ed_cmd_file), the editor exits      at the first failure.
 898 
 899 
 900        Loading an alternate malloc() library using the environment variable
 901        LD_PRELOAD can cause problems for /usr/bin/ed.
 902 
 903 
 904 
 905                                December 10, 2003                         ED(1)