ed (text editor)

from Wikipedia, the free encyclopedia

ed is a text editor available on all Unix and Unix systems that can be used interactively or within shell scripts for editing text files. It is part of the POSIX.1 standard.

Like the editors ex and EDLIN , ed works line-oriented : The text processing always refers to a line or a selection of lines. In contrast to vi , ed provides only one line for editing in interactive use, i.e. that is, it is not possible to move vertically through text with a cursor .

Like the other editors mentioned, ed has a write and a command mode. In write mode, the characters entered are added to the line that is currently being edited. In command mode, characters entered are interpreted as editing, viewing, saving, or shell commands. Text corrections or replacements are v. a. done via pattern searches using regular expressions .

ed uses very little memory resources, does not require any special program libraries to run and works with any type of terminal. ed is usually the only editor in the first binary file directory of the directory tree (/ bin) and can therefore be called whenever a program can be executed at all. The undemanding nature of the editor and its reliable availability and accessibility are the most important aspects under which it is still of interest today, especially for system administrators . Since the ed initially only requires one line of the screen for itself after being called up, it is occasionally also useful if a certain change, e.g. B. should be done in a shell script , but at the same time you don't want to lose sight of the screen output of the last started process. In addition, programs can easily be called from the editor: The screen output of the program remains visible, and you can easily continue editing the line that was worked on before calling the program.

history

ed is about as old as Unix, but already has a forerunner in the initially character-oriented, later line-oriented editor QED , which was programmed in the mid-1960s and of which there were different versions on various systems. ed was written by Ken Thompson in the early 1970s based on the GCOS version of QED implemented by Dennis Ritchie . Neither in functionality nor in appearance has it changed significantly since then. The non-interactive character stream editor sed inherits one of its basic functions from ed and expands it. Unlike sed , ed first reads the entire contents of the file into memory before executing the specified commands. The line-oriented editor ex , which forms the basis of vi , was inspired by ed . The Plan 9 editor sam is similar to ed , but breaks with line orientation and is designed as a primarily visual editor.

use

The interactive use of the ed is described in detail in the man pages of every Unix system. The following example demonstrates the non-interactive use from a shell script :

ed -s DATEI <<!
1,$s/vi/ex/g
w
q
!

In the example, ed is called with the file FILE , which is applied with an ed command specified as Heredoc :

"From the first to the last line: Replace each string vi with the string ex . Write back the edited file. Quit. "

The option -s (for script or suppress , Eng. Suppress ) while suppressing the status issues. This is usually desired in non-interactive use.

Individual evidence

  1. ed. In: The Open Group Base Specifications Issue 7. Retrieved November 22, 2016 .
  2. November 15, 2000: Re: emacs and other editors. Retrieved January 8, 2017 .

Web links