Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)

User Commands (d - f) ed(1)
subcommand accepts address 0 (for inserting lines at the beginning of the buffer). The t
subcommand sets the current line to the last line copied.
u 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 undo are a, c, d, g, G, i, j,
m, r, s, t, u, v, and V. All changes made to the buffer by a g, G, v,orV global subcom-
mand are undone as a single change. The current line number is set to the value it had
before the command being undone started.
[address1,address2]v/pattern/subcommand_list
The v subcommand executes the subcommands in subcommand_list for each line that
does not contain a match for the pattern. The v subcommand is a complement for the
global subcommand g, which executes subcommand_list for every line that does contain
a match for the pattern.
[address1,address2]V/pattern/
The V subcommand first marks every line that does not match the pattern, then displays
the first marked line, sets the current line to that line, and waits for a subcommand. The
V subcommand complements the G subcommand, which marks the lines that do match
the pattern.
[address1,address2]w file
The w
(write) subcommand copies the addressed lines from the buffer to the file named
in file.
If the file does not exist, the w subcommand creates it with permission mode 666
(read and write permission for everyone), unless the umask command setting specifies
another file creation mode. (For information about file permissions, see the description
of the builtin command umask in the reference page for sh and the reference page for
the chmod command.)
The w subcommand does not change the default filename (unless file is the first filename
used since you invoked ed). If you do not provide a filename, ed uses the default
filename, if any (see the e, E, and f subcommands). The w subcommand does not
change the current line.
If the ed command successfully writes the file, it displays the number of characters writ-
ten. When ! (exclamation point) replaces file, ed takes the rest of the line as a shell (sh)
command whose output is to be read; w does not save shell command names as default
filenames (the same effect as !). The use of the write subcommand with ! (exclamation
point) is not considered the last w subcommand that wrote the entire buffer. Thus, this
alone does not prevent the warning to the user if an attempt is made to destroy the editor
buffer through the e or q subcommands.
The address 0 is not a legal address for the w subcommand. Therefore, it is not possible
to create an empty file with the ed command.
[address]=
Without an address, the = (equal sign) subcommand displays the current line number.
With the address $, = (equal sign) displays the number of the last line in the buffer. The
= subcommand does not change the current line and cannot be included in a g or v sub-
command list.
!system_command
The ! (exclamation point) subcommand allows system commands to be run from within
the ed program. Anything following ! on an ed subcommand
line is interpreted as a sys-
tem command. Within the text of that command string, ed replaces the unescaped char-
acter %with the current filename, if there is one.
When the ! is used as the first character of a shell command (after the ! that runs a
527188-021 Hewlett-Packard Company 349