B the ed editor, Creating and saving text files, Starting the ed program – HP NonStop G-Series User Manual

Page 166: Entering text—the a (append) subcommand, Appendix b: the ed editor

Advertising
background image

B The ed Editor

This appendix explains how to create, edit, display, and save text files using the ed editor, a
line-editing program.
A good way to learn how ed works is to try the examples in this appendix on your system. Because
the examples build upon each other, it is important for you to work through them in sequence.
Also, to make what you see on the screen consistent with what you see in this guide, it is important
to do the examples just as they are given.
Because ed is a line editor, you can work with the contents of a file only one line at a time.
Regardless of what text is on the screen, you can edit only the current line. You cannot use the up
arrow (¦) and down arrow (Ø) keys to change your current line.

Creating and Saving Text Files

To create and save a text file, perform the following steps:
1.

At the shell prompt, enter:

ed filename

where filename is the name of the file you want to create or edit.

2.

When you receive the ?filename message, enter:

a

3.

Enter your text.

4.

To stop adding text, enter a period (. ) at the start of a new line.

5.

To copy the contents of the edit buffer into the file filename, enter:

w

6.

To end the ed program, enter:

q

Starting the ed Program

To start the ed program, enter a command of the form ed filename after the $ (shell) prompt.
In the following example, the ed afile command starts the ed program and indicates that you
want to work with a file named afile:

$ ed afile
?afile

The ed program responds with the message ?afile, which means that the file does not currently
exist. You can now use the a (append) subcommand (described in

“osh Flags” (page 86)

) to create

afile

and put text into it.

Entering Text—The a (Append) Subcommand

To put text into your file, enter a. The a subcommand tells ed to add, or append, the text you type
to the edit buffer. Note that if your file already contains text, the a subcommand adds the new text
to the end of the file.
Type your text, pressing the Return key at the end of each line. When you have entered all of your
text, enter a period (.) at the start of a new line.

NOTE:

If you do not press Return at the end of each line, the ed program automatically moves

your cursor to the next line after you fill a line with characters. However, ed treats everything you
type before you press Return as one line, regardless of how many lines it takes up on the screen;
that is, the line wraps around to the beginning of the next line (based upon your workstation display
settings).

The following example shows how to enter text into the file afile:

166 The ed Editor

Advertising
This manual is related to the following products: