ed
Edit text files line-by-line
TLDR
Start an interactive editor session with an empty document
Start an interactive editor session with an empty document and a specific prompt
Start an interactive editor session with user-friendly errors
Start an interactive editor session with an empty document and without diagnostics, byte counts and '!' prompt
Start an interactive editor session without exit status change when command fails
Edit a specific file (this shows the byte count of the loaded file)
Replace a string with a specific replacement for all lines
Exit ed
SYNOPSIS
ed [-p] [-s] [-x] [file]
PARAMETERS
file
The pathname of a file to be edited. If file does not exist, it is created if modified buffers are written.
-p
Enters a prompt mode. ed will display an asterisk ('*') after each command for user interaction.
-s
Enters silent mode. ed will suppress the display of character counts by 'w', 'q', and '!' commands, and informational messages.
-x
Enters encryption mode. This option is typically used with older, less secure encryption methods and is generally not recommended for sensitive data today.
DESCRIPTION
ed is the standard line-oriented text editor for Unix-like operating systems. Conceived by Ken Thompson in 1971, it stands as one of the oldest and most influential editors, fundamentally shaping subsequent tools like sed and vi. Unlike modern screen-oriented editors, ed operates in a command-line interface without a visual representation of the text. Users interact by specifying line numbers or text patterns, then applying commands to those specific lines. This makes it particularly powerful for non-interactive scripting and batch editing. Its minimalistic design, coupled with robust regular expression support, allows for complex text manipulation. Though challenging for beginners due to its lack of visual feedback and cryptic commands, ed remains invaluable in minimalistic environments, recovery scenarios, and as a core utility for shell scripting. It is the POSIX standard editor, ensuring its availability and consistent behavior across diverse Unix systems.
CAVEATS
ed is not user-friendly for interactive editing compared to screen editors like vi or emacs due to its lack of visual feedback. It requires a strong understanding of line numbers and regular expressions. A significant limitation is the absence of a standard undo/redo mechanism, making mistakes potentially permanent without careful saving. Its cryptic, terse commands can be a steep learning curve for newcomers.
BASIC COMMAND STRUCTURE
ed commands typically follow the pattern: [address][,address]command[arguments]
An address specifies which line(s) the command should operate on. If no address is given, commands usually operate on the current line or the entire buffer.
COMMON COMMANDS
- a: append text after the specified line.
- i: insert text before the specified line.
- c: change specified lines to new text.
- d: delete specified lines.
- p: print specified lines.
- s: substitute text (often with regular expressions).
- w: write buffer to a file.
- q: quit the editor.
- /pattern/: Search for a pattern.
ADDRESSING MODES
- .: The current line.
- $: The last line of the buffer.
- N: A specific line number N.
- +/-N: A line relative to the current line.
- /pattern/: The next line containing pattern.
- ?pattern?: The previous line containing pattern.
- ;: A range from the current line to the end.
- ,: A range from the first line to the last line (the entire buffer).
HISTORY
ed was originally written by Ken Thompson in 1971 for the first versions of the Unix operating system. It was one of the earliest text editors available and quickly became a fundamental utility. Its command structure and line-oriented paradigm profoundly influenced the design of subsequent text processing tools. Most notably, ed served as the inspiration for the ex editor (extended ed), which in turn became the command-line mode for vi. The stream editor sed also derives its command language directly from ed. Despite the rise of more visually interactive editors, ed's efficiency and small footprint ensured its continued relevance. It was adopted as a POSIX standard utility, cementing its place as a cornerstone of Unix-like systems, particularly useful in environments where resources are constrained or for non-interactive scripting.