Displaying text—the p (print) subcommand, Saving text—the w (write) subcommand, Saving text under the same filename – HP NonStop G-Series User Manual

Page 167

Advertising
background image

a
The only way to stop
appending is to type a
line that contains only
a period.
.

If you stop adding text to the buffer and then decide you want to add some more, enter another
a

subcommand. Type the text and then enter a period at the start of a new line to stop adding text

to the buffer.
If you make errors as you type your text, you can correct them before you press Return. Press the
Backspace key to erase the incorrect characters. Then type the correct characters in their place.

Displaying Text—The p (Print) Subcommand

Use the p (print) subcommand to display the contents of the edit buffer.
To display a single line, use the subcommand np (where n is the number of the line):

2p
appending is to type a

To display a series of lines, use the n,mp subcommand, where n is the starting line number and
m

is the ending line number:

1,3p
The only way to stop
appending is to type
a line that contains only

To display everything from a specific line to the end of the buffer, use the n,$p subcommand,
where n is the starting line number and $ stands for the last line of the buffer.
In the following example, 1,$p displays everything in the buffer:

1,$p
The only way to stop
appending is to type a
line that contains only
a period.

NOTE:

Many examples in the rest of this appendix use 1,$p to display the buffer’s contents. In

these examples, the 1,$p subcommand is optional and convenient. It lets you verify that the
subcommands in the examples work as they should.

Saving Text—The w (Write) Subcommand

The w (write) subcommand writes, or copies, the contents of the buffer into a file. You can save all
or part of a file under its original name or under a different name. In either case, ed replaces the
original contents of the file you specify with the data copied from the buffer.

Saving Text Under the Same Filename

To save the contents of the buffer under the original name for the file, enter w, as follows:

w
78

The ed program copies the contents of the buffer into the file named afile and displays the
number of characters copied into the file (78). This number includes blanks and characters such
as Return (sometimes called “newline”), which are not visible on the screen.
The w subcommand does not affect the contents of the edit buffer. You can save a copy of the file
and then continue to work with the contents of the buffer. The stored file is not changed until the
next time you use w to copy the contents of the buffer into it. As a safeguard, it is a good practice
to save a file periodically while you work on it. Then, if you make changes (or mistakes) that you
do not want to save, you can start over with the most recently saved version of the file.

Creating and Saving Text Files

167

Advertising
This manual is related to the following products: