Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought



ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



NAME
     ed, red - text editor

USAGE
     ed [ - ] [ -p string ] [ file ]

     red [ - ] [ -p string ] [ -x ] [ file ]

DESCRIPTION
     Ed is the standard text editor.  If the file argument is
     given, ed simulates an e command (see below) on the named
     file, i.e, the file is read into the ed buffer so that it
     can be edited.

     Ed operates on a copy of the file it is editing; changes
     made to the copy have no effect on the file until a w
     (write) command is given.  The copy of the text being edited
     resides in a temporary file called the buffer.  There is
     only one buffer.

     Red is a restricted version of ed.  It will only allow edit-
     ing of files in the current directory.  It prohibits execut-
     ing Shell commands via !shell command . Attempts to bypass
     these restrictions result in an error message (restricted
     Shell).

     The following size limitations apply to the text editor: 512
     characters per line, 256 characters per global command list,
     64 characters per filename, and 128K characters in the
     buffer.  The limit on the number of lines depends on the
     amount of user memory: each line takes one word.

     Commands to ed have a simple and regular structure: zero,
     one, or two addresses followed by a single-character com-
     mand, possibly followed by parameters to that command.
     These addresses specify one or more lines in the buffer.
     Every command requiring addresses has default addresses, so
     that the addresses can very often be omitted.

     To understand addressing in ed it is necessary to know that
     at any time there is a current line.  Generally speaking,
     the current line is the last line affected by a command.
     The exact effect on the current line is discussed under the
     description of each command.

     In general, only one command may appear on a line.  Certain
     commands allow the input of text.  This text is placed in
     the appropriate place in the buffer.  While ed is accepting
     text, it is in input mode.  In this mode, ed recognizes no
     commands; it merely collects all input.  Leave input mode by
     typing a period (.) alone at the beginning of a line.




Printed 6/10/85                                              ED-1





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     If an interrupt signal (ASCII DEL or BREAK) is sent, ed
     prints a question mark (?) and returns to its command level.

     Ed supports a limited form of regular expression notation.
     Regular expressions are used in addresses to specify lines
     and in some commands (e.g., s) to specify portions of a line
     that are to be substituted.  A regular expression (RE)
     specifies a set of character strings.  A member of this set
     of strings is said to be matched by the RE.

     For more specific information concerning valid commands, as
     well as the construction of addresses and regular expres-
     sions used by the text editor, see the appropriate sections
     below.

OPTIONS
     -         Suppress the printing of character counts by e, r,
               and w commands, of diagnostics from e and q com-
               mands, and of the ! prompt after a !shell command.

     -p        Specify the prompt to be equal to string.

REGULAR EXPRESSIONS
     The following one-character regular expressions (REs) match
     a single character:

     1.1    An ordinary character (not one of those discussed in
            1.2 below) is a one-character RE that matches itself.

     1.2    A backslash (\) followed by any special character is
            a one-character RE that matches the special character
            itself.  The special characters are:

            a.    ., *, [, and \ (the period, asterisk, left
                  square bracket, and backslash, respectively),
                  which are always special, except when they
                  appear within square brackets ([ ]).  Refer to
                  1.4 below.

            b.    ^ (caret), which is special at the beginning of
                  an entire RE (see 3.1 and 3.2 below), or when
                  it immediately follows the left of a pair of
                  square brackets ([ ]).  Refer to 1.4 below.

            c.    $ (dollar sign), which is special at the end of
                  an entire RE (see 3.2 below).

            d.    The character used to bound (i.e., delimit) an
                  entire RE, which is special for that RE (for
                  example, see how slash (/) is used in the g
                  command, below.)




ED-2                                              Printed 6/10/85





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     1.3    A period (.) is a one-character RE that matches any
            character except newline.

     1.4    A non-empty string of characters enclosed in square
            brackets ([ ]) is a one-character RE that matches any
            one character in that string.  If, however, the first
            character of the string is a caret (^), the one-
            character RE matches any character except newline and
            the remaining characters in the string.  The caret
            has this special meaning only if it occurs first in
            the string.  The minus sign (-) may be used to indi-
            cate a range of consecutive ASCII characters; for
            example, [0-9] is equivalent to [0123456789].  The
            minus sign loses this special meaning if it occurs
            first (after an initial caret, if any) or last in the
            string.  The right square bracket (]) does not ter-
            minate such a string when it is the first character
            within it (after an initial caret, if any); for exam-
            ple, [ ]a-f] matches either a right square bracket
            (]) or one of the letters a through f inclusive.  The
            four characters listed in 1.2.a above stand for them-
            selves within such a string of characters.

     Use the following rules to construct REs from one-character
     REs:

     2.1    A one-character RE is a RE that matches whatever the
            one-character RE matches.

     2.2    A one-character RE followed by an asterisk (*) is a
            RE that matches zero or more occurrences of the one-
            character RE.  If there is any choice, the longest
            leftmost string that permits a match is chosen.

     2.3    A one-character RE followed by \{m\}, \{m,\}, or
            \{m,n\} is a RE that matches a range of occurrences
            of the one-character RE.  The values of m and n must
            be non-negative integers less than 256; \{m\} matches
            exactly m occurrences; \{m,\} matches at least m
            occurrences; \{m,n\} matches any number of
            occurrences between m and n inclusive.  Whenever a
            choice exists, the RE matches as many occurrences as
            possible.

     2.4    The concatenation of REs is a RE that matches the
            concatenation of the strings matched by each com-
            ponent of the RE.

     2.5    A RE enclosed between the character sequences \( and
            \) is a RE that matches whatever the unadorned RE
            matches.




Printed 6/10/85                                              ED-3





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     2.6    The expression \n matches the same string of charac-
            ters matched by an expression enclosed between \( and
            \) earlier in the same RE.  Here n is a digit; the
            subexpression specified is that beginning with the
            n-th occurrence of \( counting from the left.  For
            example, the expression \(.*\)\1$ matches a line con-
            sisting of two repeated appearances of the same
            string.

     Finally, an entire RE may be constrained to match only an
     initial segment or final segment of a line (or both).

     3.1    A caret (^) at the beginning of an entire RE con-
            strains that RE to match an initial segment of a
            line.

     3.2    A dollar sign ($) at the end of an entire RE con-
            strains that RE to match a final segment of a line.

     The construction ^entire RE$ constrains the entire RE to
     match the entire line.  The null RE (e.g., //) is equivalent
     to the last RE encountered.

ADDRESSES
     Construct addresses using the following:

      1.    A period (.) addresses the current line.

      2.    A dollar sign ($) addresses the last line of the
            buffer.

      3.    A decimal number n addresses the n-th line of the
            buffer.

      4.    An 'x addresses the line marked with the mark name
            character x, which must be a lowercase letter.  Lines
            are marked with the k command described below.

      5.    A RE enclosed by slashes (/) addresses the first line
            found by searching forward from the line following
            the current line toward the end of the buffer and
            stopping at the first line containing a string match-
            ing the RE.  If necessary, the search wraps around to
            the beginning of the buffer and continues up to and
            including the current line, so that the entire buffer
            is searched.

      6.    A RE enclosed in question marks (?) addresses the
            first line found by searching backward from the line
            preceding the current line toward the beginning of
            the buffer, and stops at the first line containing a
            string matching the RE.  If necessary, the search



ED-4                                              Printed 6/10/85





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



            wraps around to the end of the buffer and continues
            up to and including the current line.  See also the
            last paragraph before FILES below.

      7.    An address followed by a plus sign (+) or a minus
            sign (-) followed by a decimal number specifies that
            address plus (or minus) the indicated number of
            lines.  The plus sign may be omitted.

      8.    If an address begins with + or -, the addition or
            subtraction is taken with respect to the current
            line; e.g, -5 is understood to mean .-5.

      9.    If an address ends with + or -, then one (1) is added
            to or subtracted from the address, respectively.  As
            a consequence of this rule and rule 8, the address of
            minus sign (-) refers to the line preceding the
            current line.  (To maintain compatibility with ear-
            lier versions of the editor, the caret (^) in
            addresses is entirely equivalent to a minus.  More-
            over, trailing plus and minus characters have a cumu-
            lative effect, so that two minus signs together (- -)
            refer to the current line less two lines.

     10.    For convenience, a comma (,) stands for the address
            pair 1,$, while a semicolon (;) stands for the pair
            .,$.

     Commands may require zero, one, or two addresses.  Commands
     that require no addresses regard the presence of an address
     as an error.  Commands that accept one or two addresses
     assume default addresses when an insufficient number of
     addresses is given.  If more addresses are given than such a
     command requires, the last one(s) are used.

     Typically, addresses are separated from each other by a
     comma (,), but they can also be separated by a semicolon
     (;).  In the latter case, the current line (.) is set to the
     first address, and only then is the second address calcu-
     lated.  This feature can be used to determine the starting
     line for forward and backward searches (see rules 5 and 6).
     The second address of any two-address sequence must
     correspond to a line that follows, in the buffer, the line
     corresponding to the first address.

COMMANDS
     In the following list of ed commands, the default addresses
     are shown in parentheses.  The parentheses are not part of
     the address; they show that the given addresses are the
     default.





Printed 6/10/85                                              ED-5





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     Usually, only one command can appear on a line.  However,
     any command (except e, f, r, or w) may be suffixed by the l,
     n, or p commands, in which case the current line is either
     listed, numbered, or printed respectively.

     If the closing delimiter of a RE or a replacement string
     (e.g., /) is the last character before a newline, you may
     omit that delimiter. Ed then prints the addressed line.  The
     following pairs of commands are equivalent:
          s/s1/s2   s/s1/s2/p
          g/s1      g/s1/p
          ?s1       ?s1?
     (.)a
     <text>
     .
          Read the given text and append it after the addressed
          line; leave . at the last inserted line, or, if there
          were none, at the addressed line.  Address 0 is legal
          for this command: it causes the ``appended'' text to be
          placed at the beginning of the buffer.  The maximum
          number of characters that may be entered from a termi-
          nal is 256 per line (including the newline character).
     (.)c
     <text>
     .
          Delete the addressed lines, then accept input text that
          replaces these lines; leave a period (.) at the last
          line input, or, if there were none, at the first line
          that was not deleted.
     (.,.)d
          Delete the addressed lines from the buffer.  The line
          after the last line deleted becomes the current line.
          If the lines deleted were originally at the end of the
          buffer, the new last line becomes the current line.
     e file
          Delete the entire contents of the buffer, and then read
          in the named file; set the current line (.) to the last
          line of the buffer.  If no filename is given, use the
          currently-remembered filename, if any (see the f com-
          mand).  The number of characters read is typed; file is
          remembered for possible use as a default filename in
          subsequent e, r, and w commands.  If file is replaced
          by !, the rest of the line is taken to be a Shell com-
          mand whose output is to be read.  Such a Shell command
          is not remembered as the current filename.  See sh (1)
          for more information about the Shell.  Refer to DIAG-
          NOSTICS below.
     E file
          Perform a function similar to the e command, except do
          not check to see whether any changes have been made to
          the buffer since the last w command.




ED-6                                              Printed 6/10/85





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     f file
          If file is given, change the currently-remembered
          filename to file; otherwise, print the currently-
          remembered filename.

     (1,$)g/RE/command list
          First, mark every line that matches the given RE.
          Then, for every such line, execute the given command
          list with period (.) initially set to that line.  A
          single command or the first of a list of commands
          appears on the same line as the global command.  All
          lines of a multi-line list except the last line must
          end with a backslash (\); a, i, and c commands and
          associated input are permitted.  The period (.) that
          terminates input mode may be omitted if it is the last
          line of the command list.  An empty command list is
          equivalent to the p command.  The g, G, v, and V com-
          mands are not permitted in the command list.

     (1,$)G/RE/
          First, mark every line that matches the given RE.
          Then, for every such line, print that line, and change
          the current line pointer (.) to that line.  Any one
          command (other than one of the a, c, i, g, G, v, and V
          commands) may then be input and executed.  After the
          execution of that command, print the next marked line,
          and so on; a newline acts as a null command; an &
          causes the re-execution of the most recent command exe-
          cuted within the current invocation of G.  Note that
          the commands input as part of the G command execution
          may address and affect any lines in the buffer.  The G
          command can be terminated by an interrupt signal (ASCII
          DEL or BREAK).
     h
          Give a short error message that explains the reason for
          the most recent diagnostic that begins with a question
          mark (?).
     H
          Enter a mode in which error messages are printed for
          all subsequent diagnostics that begin with a question
          mark (?).  Also, explain any such previous diagnostics.
          The H command alternately turns this mode on and off;
          it is initially off.
     (.)i
     <text>
     .
          Insert the given text before the addressed line; leave
          the current line pointer (.) at the last inserted line,
          or, if there were none, at the addressed line.  This
          command differs from the a command only in the place-
          ment of the input text.  Address 0 is not legal for
          this command.  The maximum number of characters that



Printed 6/10/85                                              ED-7





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



          may be entered from a terminal is 256 per line (includ-
          ing the newline character).
     (.,.+1)j
          Join contiguous lines by removing the appropriate new-
          line characters.  If exactly one address is given, this
          command does nothing.
     (.)kx
          Mark the addressed line with name x, which must be a
          lowercase letter.  The address 'x then addresses this
          line; the current line (.) is unchanged.
     (.,.)l
          Print the addressed lines in an unambiguous way.  A few
          nonprinting characters (e.g., tab, backspace) are
          represented by mnemonic overstrikes.  All other non-
          printing characters are printed in octal, and long
          lines are folded.  An l command may be appended to any
          other command other than e, f, r, or w.
     (.,.)ma
          Reposition the addressed line(s) after the line
          addressed by a.  Address 0 is legal for a, moving the
          addressed line(s) to the beginning of the file.  It is
          an error if address a falls within the range of moved
          lines; the current line (.) becomes the last line
          moved.
     (.,.)n
          Print the addressed lines, preceding each line by its
          line number and a tab character.  Leave the current
          line pointer (.) at the last line printed.  The n com-
          mand may be appended to any command other than e, f, r,
          or w.
     (.,.)p
          Print the addressed lines.  Leave the current line
          pointer (.) at the last line printed.  The p command
          may be appended to any command other than e, f, r, or
          w.  For example, dp deletes the current line and prints
          the new current line.
     P
          Prompt with an asterisk (*) for all subsequent com-
          mands.  The P command alternately turns this mode on
          and off; it is initially off.
     q
          Exit the editor.  No automatic write of a file is done.
     Q
          Exit the editor without checking to see whether changes
          have been made in the buffer since the last w command.
     ($)r file
          Read in the given file after the addressed line.  If no
          filename is given, use the currently-remembered
          filename, if any (see the e and f commands).  Do not
          change the currently-remembered filename unless file is
          the very first filename mentioned since ed was invoked.
          Address 0 is legal for r, causing the file to be read



ED-8                                              Printed 6/10/85





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



          at the beginning of the buffer.  If the read is suc-
          cessful, the number of characters read is typed and the
          current line is set to the last line read in.  If file
          is replaced by an exclamation point (!), the rest of
          the line is taken to be a Shell command whose output is
          to be read.  See sh (1) for more information about how
          the Shell operates.  For example, $r !ls appends the
          current directory to the end of the file being edited.
          Such a Shell command is not remembered as the current
          filename.

     (.,.)s/RE/replacement/         or
     (.,.)s/RE/replacement/g        or
     (.,.)s/RE/replacement/n        n = 1-512
          Search each addressed line for an occurrence of the
          specified RE.  In each line in which a match is found,
          replace all (nonoverlapped) matched strings with the
          replacement if the global replacement indicator g
          appears after the command.  If the global indicator
          does not appear, replace only the first occurrence of
          the matched string.  If a number n appears after the
          command, replace on the nth occurence of the matched
          string on each addressed line.  It is an error for the
          substitution to fail on all addressed lines.  Any char-
          acter other than space or newline may be used instead
          of / to delimit the RE and the replacement; the current
          line becomes the last line on which a substitution
          occurred.

          An ampersand (&) appearing in the replacement is
          replaced by the string matching the RE on the current
          line.  The special meaning of & in this context may be
          suppressed by preceding it with a backslash (\).  As a
          more general feature, the characters \n, where n is a
          digit, are replaced by the text matched by the nth reg-
          ular subexpression of the specified RE enclosed between
          \( and \).  When nested parenthesized subexpressions
          are present, n is determined by counting occurrences of
          \( starting from the left.  When the percent sign (%)
          is the only character in the replacement, the replace-
          ment used in the most recent substitute command is used
          as the replacement in the current substitute command.
          The percent sign loses its special meaning when it is
          in a replacement string of more than one character or
          is preceded by a backslash (\).

          A line may be split by substituting a newline character
          into it.  The newline in the replacement must be
          escaped by preceding it by a backslash.  Such substitu-
          tion cannot be done as part of a g or v command list.
     (.,.)ta
          Perform the same functions as the m command, except



Printed 6/10/85                                              ED-9





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



          place a copy of the addressed lines after address a
          (which may be 0).  The current line becomes the last
          line of the copy.
     u
          Nullify the effect of the most recent command that
          modified anything in the buffer, namely the most recent
          a, c, d, g, i, j, m, r, s, t, v, G, or V command.

     (1,$)v/RE/command list
          Perform the same functions as the g command, but exe-
          cute the command list with . initially set to every
          line that does not match the RE.

     (1,$)V/RE/
          Perform the same functions as the G command, but mark
          only those lines that do not match the RE during the
          first step.

     (1,$)w file
          Write the addressed lines into the named file.  If the
          file does not exist, create it with mode 666 (readable
          and writable by everyone), unless the umask setting
          dictates otherwise. See sh (1) for more information
          about this.  The currently-remembered filename is not
          changed unless file is the very first filename men-
          tioned since ed was invoked.  If no file name is given,
          the currently-remembered filename, if any, is used (see
          the e and f commands); the pointer to the current line
          (.) is unchanged.  If the command is successful, the
          number of characters written is typed.  If file is
          replaced by !, the rest of the line is taken to be a
          Shell command whose standard input is the addressed
          lines.  Such a Shell command is not remembered as the
          current filename.

     ($)=
          Type the line number of the addressed line without
          changing the location of the current line.

     !shell command
          Send the remainder of the line after the exclamation
          point (!) to the UNIX system Shell, sh (1), to be
          interpreted as a command.  Within the text of that com-
          mand, the unescaped percent character (%) is replaced
          with the remembered filename; if an exclamation point
          (!) appears as the first character of the Shell com-
          mand, it is replaced with the text of the previous
          Shell command.  Thus, two exclamation points in
          sequence (!!) will repeat the last Shell command.  If
          any expansion is performed, the expanded line is
          echoed; the current line is left unchanged.




ED-10                                             Printed 6/10/85





ED(1)           DOMAIN/IX Reference Manual (SYS5)           ED(1)



     (.+1)<newline>
          An address alone on a line causes the addressed line to
          be printed.  A newline alone is equivalent to .+1p; it
          is useful for stepping forward through the buffer.
CAUTIONS
     A ! command cannot be subject to a g or v command.

     The ! command and the ! escape from the e, r, and w commands
     cannot be used if the the editor is invoked from a res-
     tricted Shell.  See sh (1) for more information about the
     Shell.

     The sequence \n in a regular expression does not match a
     newline character.

     The l command mishandles DEL.

     Characters are masked to seven bits on input.

     If the editor input is coming from a command file (i.e., ed
     file < ed-cmd-file), the editor exits at the first failure
     of a command in the command file.

     When reading a file, ed discards ASCII NUL characters and
     all characters after the last newline.  Files containing
     characters not in the ASCII set (bit 8 on) cannot be edited
     using ed.
FILES
     /tmp/e#   temporary; # is the process number
     ed.hup    work is saved here if the terminal is hung up
DIAGNOSTICS
     ?         Command errors
     ?file     Inaccessible file

     If you have made changes in the buffer since the last w com-
     mand that wrote the entire buffer, ed questions attempts to
     destroy its buffer via the e or q commands.  It prints a
     question mark before allowing you to continue editing.  If
     you type a second e or q command at this point, these com-
     mands will take effect without further questioning from ed.
     The dash (-) command-line option inhibits this feature.

     Use the help and Help commands for detailed explanations.
RELATED INFORMATION
     grep (1), sed (1), sh (1), stty (1), regexp (5).










Printed 6/10/85                                             ED-11



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026