Saving text under a different filename, Saving part of a file, Ending the ed program—the q (quit) subcommand – HP NonStop G-Series User Manual

Page 168: Loading files into the edit buffer

Advertising
background image

NOTE:

The u (undo) subcommand restores the buffer to the state it was in before it was last

modified by an ed subcommand. The subcommands that u can reverse are a, c, d, g, G, i, j,
m

, r, s, t, v, and V.

Saving Text Under a Different Filename

If you have followed the previous examples, you have a file named afile that contains the original
text of your document. To create another copy of the file (while its contents are still in the buffer),
use a subcommand of the form w filename, as in the following example:

w bfile
78

At this point, afile and bfile have the same contents, because each is a copy of the same
buffer contents. However, because afile and bfile are separate files, you can change the
contents of one without affecting the contents of the other.

Saving Part of a File

To save part of a file, use a subcommand of the form n,mw filename, where:

is the beginning line number of the part of the file you want to save.

n

is the ending line number of the part of the file you want to save (or the number of a single line,
if that is all you want to save).

m

is the name of a file (optional).

filename

In the following example, the w subcommand copies lines 1 and 2 from the buffer into a new file
named cfile:

1,2w cfile
44

Then ed displays the number of characters written into cfile (44).

Ending the ed Program—The q (Quit) Subcommand

To end the ed program, enter the q (quit) subcommand:

q

The q subcommand returns you to the $ (shell) prompt.

CAUTION:

You lose the contents of the buffer when you leave the ed program. To save a copy

of the data in the buffer, use the w subcommand to copy the buffer into a file before you leave the
ed

program.

If you have changed the buffer but have not saved a copy of its contents, the q subcommand
responds with ?, an error message. At that point, you can either save a copy of the buffer with
the w subcommand or enter the q subcommand again, which lets you leave the ed program without
saving a copy of the buffer.

Loading Files Into the Edit Buffer

Before you can edit a file, you must load it into the edit buffer. You can load a file either at the
time you start the ed program or while the ed program is running.
To load a file into the edit buffer at the time you start the ed program, enter the following:

ed filename

This command starts ed and loads the file filename into the edit buffer.
To load a file into the edit buffer while ed is running, you can enter one of the following:

168 The ed Editor

Advertising
This manual is related to the following products: