ed(1)

ed(1)

NAME

ed, red - line-oriented text editor

SYNOPSIS

ed [-pstring] [-s-] [-x] [®le] red [-pstring] [-s-] [-x] [®le]

DESCRIPTION

The ed command executes a line-oriented text editor. It is most commonly used in scripts and noninteractive editing applications because, even though it can be used interactively, other editors such as vi and ex are typically easier to use in an interactive environment.

If ®le is speci®ed, ed performs an e command (see below) on the named ®le; that is to say, the ®le is read into ed's buffer so that it can be edited.

Options

The following options are recognized:

-pstring Use string as the prompt string when in command mode. By default, there is no prompt string.

-s-Suppress printing of byte counts by e, E, r, and w commands, and suppress the ! prompt after a ! command. The - option is obsolescent and will be removed in a future release.

-x

Perform an X command ®rst to handle an encrypted ®le.

File Handling

ed operates on a copy of the ®le it is editing; changes made to the copy have no effect on the original ®le until a w (write) command is given. The copy of the text being edited resides in a temporary ®le called the buffer. There is only one buffer.

red is a restricted version of ed that only allows editing of ®les in the current directory and prohibits executing shell commands via !shell-command. Attempts to bypass these restrictions result in the error message restricted shell.

Both ed and red support the fspec(4) formatting capability. After including a format speci®cation as the ®rst line of ®le and invoking ed with the controlling terminal in stty -tabsor stty tab3 mode (see stty(1)), the speci®ed tab stops are automatically used when scanning ®le. For example, if the ®rst line of a ®le contained

<:t5,10,15 s72:>

the tab stops would be set at columns 5, 10, and 15, and a maximum line length of 72 would be imposed.

Note: When you input text, ed expands tab characters as they are typed to every eighth column as a default.

Editor Commands Structure

Commands to ed have a simple and regular structure: zero, one, or two addresses followed by a single- character command, possibly followed by parameters to that command. These addresses specify one or more lines in the buffer. Every command that requires addresses has default addresses, so that the addresses can very often be omitted.

In general, only one command is allowed on a line. Append, change, and insert commands accept text input which is then placed in the buffer as appropriate. While ed is accepting text following an append, change, or insert command, it is said to be in input mode. While in input mode, no editor commands are recognized; all input is merely collected. To terminate input mode, type a period (.) alone at the beginning of a line.

Regular Expressions

ed supports the Basic Regular Expression (RE) syntax (see regexp(5)), with the following additions:

The null RE (for example, //) is equivalent to the last RE encountered.

If the closing delimiter of an RE or of a replacement string (for example, /) would be the last char- acter before a newline, that delimiter can be omitted, in which case the addressed line is printed. The following pairs of commands are equivalent:

HP-UX Release 11i: December 2000

− 1 −

Section 1195

e