FreeBSD Manual Pages
ed(1) General Commands Manual ed(1) NAME ed, red - line-oriented text editor SYNOPSIS string] [file] string] [file] DESCRIPTION The 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 and are typ- ically easier to use in an interactive environment. If file is specified, performs an command (see below) on the named file; that is to say, the file is read into buffer so that it can be edited. Options The following options are recognized: Use string as the prompt string when in command mode. By default, there is no prompt string. Suppress printing of byte counts by and commands, and suppress the prompt after a com- mand. The option is obsolescent and will be removed in a future release. Perform an command first to handle an encrypted file. File Handling operates on a copy of the file it is editing; changes made to the copy have no effect on the original file until a (write) command is given. The copy of the text being edited resides in a temporary file called the buffer. There is only one buffer. is a restricted version of that only allows editing of files in the current directory and prohibits executing shell commands via Attempts to bypass these restrictions result in the error message Both and support the fspec(4) formatting capability. After including a format specification as the first line of file and invoking with the controlling terminal in or mode (see stty(1)), the specified tab stops are automatically used when scanning file. For example, if the first line of a file contained the tab stops would be set at columns 5, 10, and 15, and a maximum line length of 72 would be imposed. When you input text, expands tab characters as they are typed to every eighth column as a default. Editor Commands Structure Commands to have a simple and regular structure: zero, one, or two ad- dresses 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 ad- dresses, 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 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 supports the Basic Regular Expression (RE) syntax (see regexp(5)), with the following additions: o The null RE (for example, is equivalent to the last RE en- countered. o If the closing delimiter of an RE or of a replacement string (for example, would be the last character before a newline, that delimiter can be omitted, in which case the addressed line is printed. The following pairs of commands are equiva- lent: s/s1/s2 g/s1 ?s1 s/s1/s2/p g/s1/p ?s1? Line Addresses To understand line addressing, remember that maintains a pointer to the current line. Generally speaking, the current line is the last line affected by a command. The exact effect of a given command on the cur- rent line is discussed under the description of each command. Ad- dresses are interpreted according to the following rules: 1. The character refers to the current line. 2. The character refers to the last line of the buffer. 3. A decimal number n refers to the nth line of the buffer. 4. A refers to the line marked with the mark name character x, which must be a lower-case letter. Lines are marked with the command described below. 5. An RE enclosed by slashes () refers to the first line found by searching forward from the line following the current line toward the end of the buffer and stopping at the first line containing a string matching the RE. If necessary, the search wraps around to the beginning of the buffer and con- tinues up to and including the current line, so that the en- tire buffer is searched. (Also see WARNINGS below.) 6. An RE enclosed by question marks () addresses the first line found by searching backward from the line preceding the cur- rent line toward the beginning of the buffer and stopping at the first line containing a string matching the RE. If nec- essary, the search wraps around to the end of the buffer and continues up to and including the current line. (Also see WARNINGS below.) 7. An address followed by a plus or minus sign followed by a decimal number specifies that address plus or minus the in- dicated number of lines. The plus sign can be omitted. 8. If an address begins with or the addition or subtraction is calculated with respect to the current line. For example, is interpreted as 9. If an address ends with or 1 is added to or subtracted from the address, respectively. As a consequence of this and rule 8 above, the address refers to the line preceding the current line. (To maintain compatibility with earlier ver- sions of the editor, the circumflex and characters are in- terpreted identically when encountered in addresses.) More- over, multiple trailing and characters have a cumulative ef- fect, so refers to the second line preceding the current line. 10. For convenience, a comma represents the address pair while a semicolon represents the pair Commands require zero, one, or two addresses. Commands that do not use addresses treat the presence of an address as an error. Commands that accept one or two addresses assume default addresses when the number of addresses specified is insufficient. If more addresses are specified than a given command requires, the last one or two are used as appro- priate. Addresses are usually separated from each other by a comma They can also be separated by a semicolon in which case the current line is set to the first address, after which the second address is calculated. This feature can be used to determine the starting line for forward and backward searches (see rules 5 and 6 above). The second address of any two-address sequence must correspond to a line in the buffer that fol- lows the line corresponding to the first address. Editor Commands In the following list of commands, the default addresses are shown in parentheses (parentheses are not part of the address and should not be placed in an actual command except for other purposes). It is generally illegal for more than one command to appear on a line. However, any command (except or can be suffixed by or in which case the current line is respectively either listed, numbered, or printed, as discussed below under the and commands. text The (append) command reads text and appends it after the ad- dressed line. Upon completion, the new current line is the last inserted line, or, if no text was added, at the addressed line. Address 0 is legal for this command, causing the appended text to be placed at the beginning of the buffer. text The (change) command deletes the addressed lines then ac- cepts input text to replace the deleted lines. Upon completion, the new current line is the last line in text or, if no text was provided, at the first line af- ter the deleted line or lines. The (delete) command deletes the addressed lines from the buffer. Upon completion, the new current line is the first line following the deleted text, or the last line in the file if the deleted line or lines were at the end of the buffer. The (edit) command deletes the entire contents of the buf- fer, then reads in the named file. Upon completion, the new current line is the last line in the buffer. If no file name is given, the remembered file name, if any, is used (see the command). The number of characters read is displayed, and file is remembered for possible use as a default file name in subsequent or commands. If the file name starts with the rest of the line is in- terpreted as a shell command whose standard output is to be read. Such a shell command is not remembered as the current file name. Also see DIAGNOSTICS below. The (forced edit) command is identical to except that no check is made to ensure that the current buffer has not been altered since the last command. If file is specified, the (file name) command changes the remembered file name to file. Otherwise, it prints the remembered file name. The (global) command first marks every line that matches the given RE. Then, for every such line, the given command- list is executed with the current line initially set to that line. A single command or the first of a list of commands appears on the same line as the global command. All lines of a multiple-line list except the last line must end with a backslash and commands and associated input are permitted. The that normally terminates input mode can be omitted if it would be the last line of the command-list. An empty command-list is equivalent to the command. The and commands are not permitted in the command-list. (Also see WARNINGS below.) The interactive (Global) command first marks every line that matches the given RE. Then, for every such line, the line is printed, then the current line is changed to that line and one command (other than or can be input and exe- cuted. After executing that command, the next marked line is printed, and so on. A newline character acts as a null command, and an causes the re-execution of the most recent command executed within the current invoca- tion of Note that the commands input as part of the exe- cution of the command may address and affect any lines in the buffer. The command can be terminated by an in- terrupt signal (ASCII DEL or BREAK). The (help) command gives a short error message explaining the reason for the most recent diagnostic. The (Help) command causes to enter a mode in which error messages are printed for all subsequent diagnostics. It also explains the previous if there was one. The com- mand alternately turns this mode on and off. Initially, it is off. text The (insert) command inserts the given text before the ad- dressed line. Upon completion, the current line is the last inserted line, or, if there were none, the ad- dressed line. This command differs from the command only in the placement of the input text. Address 0 is not legal for this command. The (join) command joins contiguous lines by removing the appropriate newline characters. If exactly one address is given, this command does nothing. The (mark) command marks the addressed line with the name x, which must be a lower-case letter. The address then ad- dresses this line. Upon completion, the new current line remains unchanged from before. The (list) command writes the addressed lines to standard output in a visually unambiguous form. Characters listed in the following table are written as the corre- sponding escape sequence. Nonprintable characters not in the table are written as a three-digit octal number (with a preceding backslash character) for each byte in the character (most significant byte first). Long lines are folded with the point of folding indi- cated by writing a backslash character followed by a newline. The end of each line is marked with a An (ell) command can be appended to any command other than or The current line number is set to the address of the last line written. | Escape ASCII | Escape ASCII Sequence Represents Name | Sequence Represents Name \\ backslash \ | \r carriage return CR \a alert BEL | \t horizontal tab HT \b backspace BS | \v vertical tab VT \f formfeed FF | The (move) command repositions the addressed lines after the line addressed by a. Address 0 is legal for a, causing the addressed lines to be moved to the beginning of the file. It is an error if address a falls within the range of moved lines; Upon completion, the new current line is the last line moved. The (number) command prints the addressed lines, preceding each line by its line number and a tab character. Upon completion, the new current line is the last line printed. The command can be appended to any command other than or The (print) command prints the addressed lines. Upon com- pletion, the new current line is the last line printed. The command may be appended to any other command other than or For example, deletes the current line and prints the new current line. The (prompt) command causes to prompt with an asterisk (or with string if the option was specified in the command line) for all subsequent commands. The command alter- nately turns this mode on and off. It is initially on if the option was specified; otherwise, off. The cur- rent line number is unchanged. The (quit) command causes to exit. No automatic write of a file is done (but see DIAGNOSTICS below). The editor exits unconditionally without checking for changes in the buffer since the last command. The (read) command reads the specified file into the buffer after the addressed line. If no file name is given, the remembered file name, if any, is used (see the and com- mands). The remembered file name is not changed unless file is the very first file name mentioned since was in- voked. Address 0 is legal for and places the contents of file at the beginning of the buffer. If the read is successful, the number of characters read is displayed. Upon completion, the new current line is the last line read into the buffer. If the file name starts with the rest of the line is interpreted as a shell command whose standard output is to be read. For example, appends a listing of files in the current directory to the end of the file being edited. A shell command is not remem- bered as the current file name. The (substitute) command searches each addressed line for an occurrence of the specified RE. In each line in which a match is found, all (nonoverlapped) matched strings are replaced by replacement if the global replacement indi- cator appears after the command. If the global indica- tor does not appear, only the first occurrence of the matched string is replaced. If a number n appears after the command, only the nth occurrence of the matched string on each addressed line is replaced. It is an er- ror for the substitution to fail on all addressed lines. Any character other than space or newline can be used instead of to delimit the RE and replacement. Upon com- pletion, the new current line is the last line on which a substitution occurred. (Also see WARNINGS below.) If an ampersand appears in replacement, it is replaced by the string matching the RE on the current line. The special meaning of in this context can be suppressed by preceding it with As a more general feature, the characters where n is a digit, are replaced by the text matched by the nth regu- lar subexpression of the specified RE enclosed between and When nested parenthesized subexpressions are present, n is determined by counting occurrences of starting from the left. When the character is the only character in replacement, the replacement used in the most recent substitute com- mand is used as the replacement in the current substi- tute command. The loses its special meaning when it is in a replacement string containing more than one charac- ter or when preceded by a A line can be split by substituting a newline character into it. The newline in replacement must be escaped by preceding it by Such substitution cannot be done as part of a or command list. The value of flags is zero or more of: n Substitute for the nth occurrence only of the RE found on each addressed line. Substitute for all nonoverlapped occurrences of the RE on each addressed line. Write to standard output the final line in which a substitution was made. The line is written in the format specified for the command. Write to standard output the final line in which a substitution was made. The line is written in the format specified for the command. Write to standard output the final line in which a substitution was made. The line is written in the format specified for the command. Same as command, except that a copy of the addressed lines is placed after address a (which can be 0). Upon comple- tion, the new current line is the last line of the copy. The (undo) command nullifies the effect of the most recent command that modified anything in the buffer, that is, the most recent or command. All changes made to the buffer by a or global command are "undone" as a single change; if no changes were made by the global command (such as with ), the command has no effect. The current line number is set to the value it had immediately be- fore the command started. The complement of the global command in that the lines marked during the first step are those that do match the RE. The complement of the interactive global command in that the lines marked during the first step are those that do match the RE. The (write) command writes the addressed lines into the named file. If the file does not exist, it is created with mode 666 (readable and writable by everyone), un- less the current setting dictates otherwise (see umask(1). The remembered file name is not changed un- less file is the very first file name encountered since was invoked. If no file name is given, the remembered file name, if any, is used (see the and commands). Upon completion, the current line address is unchanged. If the command is successful, the number of characters written is displayed. If the file name starts with the rest of the line is in- terpreted as a shell command whose standard input is the addressed lines. Such a shell command is not remembered as the current file name. A key string is demanded from the standard input. Subsequent and commands will encrypt and decrypt the text with this key, using the algorithm of crypt(1). An explicitly empty key turns off encryption. The line number of the addressed line is displayed. The current line address is unchanged by this command. The remainder of the line after the is sent to the shell to be interpreted and executed as a command. Within the text of that command, the unescaped character is replaced with the remembered file name. If a appears as the first character of the shell command, it is replaced with the text of the previous shell com- mand. Thus, repeats the last shell command. If any ex- pansion is performed, the expanded line is echoed. Upon completion, the current line address is unchanged. An address alone on a line causes the addressed line to be printed. A newline alone is equivalent to This technique is use- ful for stepping forward through the buffer. If an interrupt signal (ASCII DEL or BREAK) is sent, prints a and re- turns to its command level. The following size limitations apply: 256 characters per global command list, 64 characters per file name, and 32 MB characters in the buffer. The limit on the number of lines depends on the amount of user memory: each line takes 1 word. EXTERNAL INFLUENCES Environment Variables determines the preferred command-line interpreter for use in all com- mands. If this variable is null or not set, the POSIX shell, is used (see sh-posix(1)). When set, specifies a directory to be used for temporary files, over- riding the default directory, provides a default value for internationalization variables that are unset or null. If is unset or null, the default value is "C" (see lang(5)). If any internationalization variable contains an invalid setting, all internationalization variables default to "C". See envi- ron(5). If is set to a nonempty string value, it overrides the values of all the other internationalization variables, including determines the interpretation of text as single- and/or multibyte char- acters, the classification of characters as printable, and the charac- ters matched by character class expressions in regular expressions. determines the locale that should be used to affect the format and con- tents of diagnostic messages written to standard error and informative messages written to standard output. determines the location of message catalogues for the processing of International Code Set Support Single- and multibyte character code sets are supported. DIAGNOSTICS Command error. Use or to get a detailed explanation. Inaccessible file. Use or to get a detailed explanation. If changes have been made in the buffer since the last command that wrote the entire buffer, warns you if you attempt to destroy the buffer with an or command. displays or then continues normal editing unless you enter a second or command, in which case the second command is exe- cuted. The or command-line option inhibits this feature. EXAMPLES Make a simple substitution in from a shell script, changing the first occurrence of in any line to and save the changes in Note that, if a command fails, the editor exits immediately. WARNINGS A command cannot be subject to a or a command. The command and the escape from the and commands cannot be used if the the editor is invoked from a restricted shell (see sh(1)). The sequence in a regular expression does not match a newline charac- ter. The command does not handle DEL correctly. Files encrypted directly with the command with the null key cannot be edited (see crypt(1)). If the editor input is coming from a command file (e.g., the editor ex- its at the first failure of a command in the command file. When reading a file, discards ASCII NUL characters and all characters after the last newline. This can cause unexpected behavior when using regular expressions to search for character sequences containing NUL characters or text near end-of-file. AUTHOR was developed by HP and OSF. FILES Temporary buffer file where p is the process number. Work is saved here if the terminal is hung up. SEE ALSO awk(1), csh(1), crypt(1), ex(1), grep(1), ksh(1), sed(1), sh(1), sh- posix(1), stty(1), vi(1), fspec(4), environ(5), lang(5), regexp(5). The section in STANDARDS CONFORMANCE ed(1)
NAME | SYNOPSIS | DESCRIPTION | EXTERNAL INFLUENCES | DIAGNOSTICS | EXAMPLES | WARNINGS | AUTHOR | FILES | SEE ALSO | STANDARDS CONFORMANCE
Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=ed&sektion=1&manpath=HP-UX+11.22>