Creating and saving a text file

  1. To begin editing a new file, enter:
    ed filename
    where filename is the name of a new file.
  2. After you see the ?filename message, enter:
    a
    This indicates that you want to append lines.
  3. Type your text. At the end of each line, press <Enter>. You can then enter more text.
  4. When you have finished entering text, enter:
    .
    (a period) at the start of a new line.
  5. To write the contents of the edit buffer to the file filename, enter:
    w
    After writing to the file, the shell displays the number of characters that were copied—for example, 746. This number includes blanks and newline characters appended to each line of text, which you cannot see on the screen.
    If you want to write to a file different from the original filename, specify a different filename when you enter the w subcommand; for example:
    w diffname

    Entering the w subcommand does not change the contents of the buffer.

  6. To exit the ed program, enter:
    q
    This deletes the contents of the buffer.