ed: The original Unix text editor

The ed command is a text editor that was one of the original Unix utilities. It is a line-oriented editor designed for use in a terminal environment and follows a minimalist approach. ed allows users to create, edit, and manipulate text files directly from the command line.

Here’s a more detailed explanation of the ed command:

  • Line-Oriented Editing: ed operates on a line-by-line basis, where each line of text in the file is assigned a unique number. The user can refer to specific lines using these line numbers to perform various editing operations.
  • Basic Editing Commands: ed provides a set of basic editing commands that allow users to perform operations such as inserting or appending text, deleting lines, searching for patterns, replacing text, moving or copying lines, and saving changes to the file.
  • Command-Line Interface (CLI): ed is used entirely from the command line, making it suitable for scripting and automation purposes. Users enter commands in response to a command prompt, and ed executes the corresponding editing operation.
  • Batch Mode: ed can also be used in a batch mode, where a sequence of editing commands can be stored in a file and passed as input to ed, allowing for automated editing operations.
  • Portability: ed is designed to be highly portable across different Unix-like systems and has a standardized behavior defined by the POSIX standard. This means that scripts or commands written using ed are more likely to work consistently across various Unix platforms.
  • Line-Addressing: ed allows for precise manipulation of specific lines using line-addressing syntax. This syntax can include line numbers, regular expressions, or relative line references, providing flexibility in targeting specific sections of a file for editing.
  • Direct File Manipulation: Unlike modern full-screen text editors, ed does not provide a visual interface or on-screen editing capabilities. Instead, it operates directly on the file, making it a lightweight and efficient tool for editing large files or working on systems with limited resources.

While ed has a steep learning curve compared to more modern text editors, it remains a powerful tool for text editing and manipulation in Unix-like environments. It is still widely used in scripts, automation workflows, and situations where a lightweight and scriptable text editor is required.

ed Command Examples

1. Start an interactive editor session with an empty document:

# ed

2. Start an interactive editor session with an empty document and a specific prompt:

# ed --prompt='> '

3. Start an interactive editor session with user-friendly errors:

# ed --verbose

4. Start an interactive editor session with an empty document and without diagnostics, byte counts and ‘!’ prompt:

# ed --quiet

5. Start an interactive editor session without exit status change when command fails:

# ed --loose-exit-status

6. Edit a specific file (this shows the byte count of the loaded file):

# ed path/to/file

7. Replace a string with a specific replacement for all lines:

,s/regular_expression/replacement/g
Related Post