ed (software)
Cross-platform | |
Type | Text editor |
---|---|
License | Plan 9: MIT License |
ed (pronounced as distinct letters, /ˌiːˈdiː/)[1] is a line editor for Unix and Unix-like operating systems. It was one of the first parts of the Unix operating system that was developed, in August 1969.[2] It remains part of the POSIX and Open Group standards for Unix-based operating systems,[3] alongside the more sophisticated full-screen editor vi.
History and influence
The ed text editor was one of the first three key elements of the Unix operating system—
g/re/p
performs a global regular expression search and prints the lines containing matches. The Unix stream editor, sed implemented many of the scripting features of qed that were not supported by ed on Unix.[6][failed verification][7]Features
Features of ed include:
- available on essentially all Unix systems (and mandatory on systems conforming to the Single Unix Specification).
- support for regular expressions
- powerful automation can be achieved by feeding commands from standard input
(In)famous for its terseness, ed, compatible with
In current practice, ed is rarely used interactively, but does find use in some
The version of ed provided by GNU has a few switches to enhance the feedback. Using ed -v -p:
provides a simple prompt and enables more useful feedback messages.[10] The -p
switch is defined in POSIX since XPG2 (1987).[3]
The ed commands are often imitated in other line-based editors. For example,
and descendants, for example) use ed-like syntax. These editors, however, are typically more limited in function.Example
Here is an example transcript of an ed session. For clarity, commands and text typed by the user are in normal face, and output from ed is emphasized.
a
ed is the standard Unix text editor.
This is line number two.
.
2i
.
,l
ed is the standard Unix text editor.$
$
This is line number two.$
w text
63
3s/two/three/
,l
ed is the standard Unix text editor.$
$
This is line number three.$
w text
65
q
The end result is a simple text file containing the following text:
ed is the standard Unix text editor. This is line number three.
Started with an empty file, the a
command appends text (all ed commands are single letters). The command puts ed in insert mode, inserting the characters that follow and is terminated by a single dot on a line. The two lines that are entered before the dot end up in the file buffer. The 2i
command also goes into insert mode, and will insert the entered text (a single empty line in our case) before line two. All commands may be prefixed by a line number to operate on that line.
In the line ,l
, the lowercase L stands for the list command. The command is prefixed by a range, in this case ,
which is a shortcut for 1,$
. A range is two line numbers separated by a comma ($
means the last line). In return, ed lists all lines, from first to last. These lines are ended with dollar signs, so that white space at the end of lines is clearly visible.
Once the empty line is inserted in line 2, the line which reads "This is line number two." is now actually the third line. This error is corrected with 3s/two/three/
, a substitution command. The 3
will apply it to the correct line; following the command is the text to be replaced, and then the replacement. Listing all lines with ,l
the line is shown now to be correct.
w text
writes the buffer to the file "text" making ed respond with 65, the number of characters written to the file. q
will end an ed session.
Cultural references
The
ED
with its description (errorstr) merely a single question mark, noting "the experienced user will know what is wrong."[11]See also
- Edlin, the standard MS-DOS line editor which was inspired by ed
- Sam (text editor)
- Editor war
- List of Unix commands
References
- ^ Computerphile (2018-07-06), Where GREP Came From – Computerphile, archived from the original on 2021-12-11, retrieved 2020-10-21
- ^ a b c Salus, Peter H. (2005). The Daemon, the Gnu and the Penguin. Groklaw. Archived from the original on 2010-05-05.
- ^ The Single UNIX Specification, Version 4 from The Open Group
- ^ D. M. Ritchie and K. L. Thompson, "QED Text Editor", MM-70-1373-3 (June 1970), reprinted as "QED Text Editor Reference Manual", MHCC-004, Murray Hill Computing, Bell Laboratories (October 1972).
- McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986(PDF) (Technical report). CSTR. Bell Labs. 139.
- ^ Raymond, Eric (2003). "The Art of Unix Programming" (PDF). Archived (PDF) from the original on June 15, 2023. Retrieved June 14, 2023.
- ^
"On the Early History and Impact of Unix".
A while later a demand arose for another special-purpose program, gres, for substitution: g/re/s. Lee McMahon undertook to write it, and soon foresaw that there would be no end to the family: g/re/d, g/re/a, etc. As his concept developed it became sed…
- ^ a b Donald A. Norman (1981). "The truth about UNIX" (PDF). Datamation. Archived from the original (PDF) on 2014-04-16.
- ^ Administering SQL*Plus. Accessed 7/23/2016.
- ^ Linux General Commands Manual –
- ^ "The GNU C Library - Error Codes". www.gnu.org.
External links
- The Single UNIX Specification, Version 4 from The Open Group
: edit text – Shell and Utilities Reference,
- Manual page from Unix First Edition describing ed.
- Version 7 Unix Programmer's Manual : text editor –
- Plan 9 Programmer's Manual, Volume 1, a direct descendant of the original ed. : text editor –
- GNU ed homepage
- A History of UNIX before Berkeley section 3.1 describes the history of ed.