LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

ed

standard Unix line editor

TLDR

Start ed with file
$ ed [file.txt]
copy
Print line 5
$ 5p
copy
Print all lines
$ ,p
copy
Substitute text
$ s/old/new/
copy
Substitute globally on line
$ s/old/new/g
copy
Append after current line
$ a
copy
Write and quit
$ wq
copy
Edit a file non-interactively by piping commands to ed
$ printf '%s\n' ',s/old/new/g' 'w' 'q' | ed -s [file.txt]
copy

SYNOPSIS

ed [options] [file]

DESCRIPTION

ed is the standard Unix line editor. It operates in command mode by default, accepting single-letter commands to navigate, view, and modify text. It's the ancestor of sed and vi.Commands typically consist of an address or range followed by a command letter. Addresses can be line numbers, patterns, or special characters (. for current, $ for last line).ed is useful for scripted editing, as commands can be piped to it. Its minimal interface makes it valuable for emergency system recovery when full-screen editors aren't available.

PARAMETERS

FILE

File to edit.
-p STRING, --prompt=STRING
Use STRING as the command prompt (there is no prompt by default).
-s, --quiet, --script
Suppress diagnostics, byte counts and the '!' prompt: the usual choice for scripts.
-E, --extended-regexp
Use extended regular expressions instead of basic ones.
-G, --traditional
Run in compatibility mode with the traditional Unix ed.
-l, --loose-exit-status
Exit with 0 status even if a command fails.
-r, --restricted
Restricted mode: disallow shell escapes and editing files outside the current directory.
-v, --verbose
Print full error messages rather than a bare '?'.
--help
Display help and exit.
--version
Display version and exit.

CAVEATS

No visual feedback by default. Errors reported with "?" unless verbose. Learning curve for command syntax. Not suitable for casual editing.

HISTORY

ed was written by Ken Thompson at Bell Labs in 1969, making it one of the earliest Unix programs. Its design influenced sed, ex, vi, and ultimately modern text editors.

SEE ALSO

sed(1), vi(1), ex(1)

RESOURCES

Copied to clipboard
Kai