Owner's manual

e filename
This command loads the file filename into the buffer, erasing any previous contents of the
buffer.
nr filename
This command reads the named file into the buffer after line n. If you do not specify n, ed adds
the file to the end of the buffer.
Using the ed (Edit) Command
To load a file into the edit buffer when you start the ed program, simply type the name of the file
after the ed command. The ed command in the following example invokes the ed program and
loads the file afile into the edit buffer:
$ ed afile
78
The ed program displays the number of characters that it read into the edit buffer (78).
If ed cannot find the file, it displays ?filename. To create that file, use the a (append)
subcommand, described in osh Flags” (page 86), and the w (write) subcommand, described in
“Saving Text—The w (Write) Subcommand” (page 167).
Using the e (Edit) Subcommand
Once you start the ed program, you can use the e (edit) subcommand to load a file into the buffer.
The e subcommand replaces the contents of the buffer with the new file. (Compare the e
subcommand with the r subcommand, described in “Using the r (Read) Subcommand” (page 169),
which adds the new file to the contents of the buffer.)
CAUTION: When you load a new file into the buffer with the e subcommand, the new file replaces
the buffer’s previous contents. Save a copy of the buffer with the w subcommand before you read
a new file into the buffer.
In the following example, the subcommand e cfile reads the file cfile into the edit buffer,
replacing afile. The e afile subcommand then loads afile back into the buffer, deleting
cfile. The ed program returns the number of characters read into the buffer after each e
subcommand (44 and 78):
e cfile
44
e afile
78
If ed cannot find the file, it returns ?filename. To create that file, use the a (append) subcommand,
described in osh Flags (page 86), and the w (write) subcommand, described in “Saving Text—The
w (Write) Subcommand” (page 167).
You can edit any number of files, one at a time, without leaving the ed program. Use the e
subcommand to load a file into the buffer. After making your changes to the file, use the w
subcommand to save a copy of the revised file. See “Saving Text—The w (Write) Subcommand”
(page 167) for information about the w subcommand. Then use the e subcommand again to load
another file into the buffer.
Using the r (Read) Subcommand
After you have started the ed program, you can use the r (read) subcommand to read a file into
the buffer. The r subcommand adds the contents of the file to the contents of the buffer. The r
subcommand does not delete the contents of the buffer. (Compare the r subcommand with the e
subcommand, described in “Displaying Directories (ls -F)” (page 116), which deletes the contents
of the buffer before it reads in another file.)
With the r subcommand, you can read a file into the buffer at a particular place. For example,
the 4r cfile subcommand reads the file cfile into the buffer following line 4. The ed program
Loading Files Into the Edit Buffer 169