ed: Overview

 
 1 Overview
 **********
 
 GNU ed is a line-oriented text editor. It is used to create, display, modify
 and otherwise manipulate text files, both interactively and via shell
 scripts. A restricted version of ed, red, can only edit files in the current
 directory and cannot execute shell commands. Ed is the 'standard' text
 editor in the sense that it is the original editor for Unix, and thus widely
 available. For most purposes, however, it is superseded by full-screen
 editors such as GNU Emacs or GNU Moe.
 
    GNU ed is based on the editor algorithm described in Brian W. Kernighan
 and P. J. Plauger's book "Software Tools in Pascal", Addison-Wesley, 1981.
 
    If invoked with a FILE argument, then a copy of FILE is read into the
 editor's buffer. Changes are made to this copy and not directly to FILE
 itself. Upon quitting 'ed', any changes not explicitly saved with a 'w'
 command are lost. In interactive mode, a non-existing FILE is reported but
 does not alter the exit status.
 
    Editing is done in two distinct modes: "command" and "input". When first
 invoked, 'ed' is in command mode. In this mode commands are read from the
 standard input and executed to manipulate the contents of the editor
 buffer. A typical command might look like:
 
      ,s/OLD/NEW/g
 
    which replaces all occurences of the string OLD with NEW.
 
    When an input command, such as 'a' (append), 'i' (insert) or 'c'
 (change), is given, 'ed' enters input mode. This is the primary means of
 adding text to a file. In this mode, no commands are available; instead,
 the standard input is written directly to the editor buffer. A "line"
 consists of the text up to and including a <newline> character. Input mode
 is terminated by entering a single period ('.') on a line.
 
    All 'ed' commands operate on whole lines or ranges of lines; e.g., the
 'd' command deletes lines; the 'm' command moves lines, and so on. It is
 possible to modify only a portion of a line by means of replacement, as in
 the example above. However even here, the 's' command is applied to whole
 lines at a time.
 
    In general, 'ed' commands consist of zero or more line addresses,
 followed by a single character command and possibly additional parameters;
 i.e., commands have the structure:
 
      [ADDRESS[,ADDRESS]]COMMAND[PARAMETERS]
 
    The ADDRESSes indicate the line or range of lines to be affected by the
 command. If fewer addresses are given than the command accepts, then
 default addresses are supplied.