.\" @(#)e2 6.1 (Berkeley) 5/22/86
Writing text out as a file \- the Write command ``w''
It's likely that you'll want to save your text for later use.
To write out the contents of the buffer onto a file,
followed by the filename you want to write on.
This will copy the buffer's contents
(destroying any previous information on the file).
the number of characters it wrote out.
(Remember that blanks and the return character at the end of each
line are included in the character count.)
Writing a file just makes a copy of the text \- the
buffer's contents are not disturbed, so you can go on adding
This is an important point.
at all times works on a copy
of a file, not the file itself.
No change in the contents
of a file takes place until you give a
(Writing out the text onto a file from time to time as it is being
created is a good idea, since if the system crashes or if you make some horrible mistake, you will lose
all the text in the buffer but any text that was written onto
a file is relatively safe.)
Leaving ed \- the Quit command ``q''
To terminate a session with
save the text you're working on
by writing it onto a file using the
and then type the command
The system will respond with
this point your buffer vanishes, with all its text,
which is why you want to write it out before quitting.\(dg
if you try to quit without writing.
At that point, write if you want;
will get you out regardless.
command, and print the file,
to see that everything worked.
Reading text from a file \- the Edit command ``e''
A common way to get text into the buffer is to read it
from a file in the file system.
This is what you do to edit text
command in a previous session.
fetches the entire contents of a file into the buffer.
So if you had saved the three lines
``Now is the time'', etc.,
command in an earlier session,
would fetch the entire contents of the file
into the buffer, and respond
which is the number of characters in
If anything was already in the buffer, it is deleted first.
command to read a file into the buffer,
then you need not use a file name after a subsequent
remembers the last file name used in an
Thus a good way to operate is
This way, you can simply say
and be secure in the knowledge that
if you got the file name right at the beginning,
you are writing into the proper file each time.
You can find out at any time what file name
is remembering by typing the
Reading text from a file \- the Read command ``r''
Sometimes you want to read a file into the buffer
without destroying anything that is already there.
to the end of whatever is already in the buffer.
So if you do a read after
copies of the text (six lines).
to come to the aid of their party.
to come to the aid of their party.
number of characters read in, after the reading operation is complete.
try reading and printing various files.
this means that the file doesn't exist,
typically because you spelled the file name wrong,
or perhaps that you are not allowed to read or write it.
Try alternately reading and appending to see that they work
Printing the contents of the buffer \- the Print command ``p''
or list the contents of the buffer (or parts
of it) on the terminal, use the print command
The way this is done is as follows.
you want printing to begin and where you want it to end,
separated by a comma, and
Thus to print the first two lines of the buffer, for
example, (that is, lines 1 through 2) say
1,2p (starting line=1, ending line=2 p)
Suppose you want to print
as above if you knew there were exactly
But in general, you don't
know how many there are, so what do you use for the ending
provides a shorthand symbol for ``line number of
last line in buffer'' \- the dollar sign
the lines in the buffer (line 1 to last line.)
If you want to stop the printing before it is finished,
and wait for the next command.
line of the buffer, you could use
lets you abbreviate this to
You can print any single line by typing the line
which is the first line of the buffer.
lets you abbreviate even further:
you can print any single line by typing
the line number \- no need to type the letter
will print the last line of the buffer.
which prints the last two lines of the buffer.
This helps when you want to see how far you got in typing.
As before, create some text using the
You will find, for example,
that you can't print line 0 or a line beyond
the end of the buffer, and that attempts
to print a buffer in reverse order by saying