Last Updated : 01 Nov, 2024
Linux 'ed' command is used to start the ed text editor, a very minimal fronted line-based text editor. The lines are very simple in relation to other text files, hence easy to work on, for creating as well as editing, display, and manipulation of files.
Since it was the first editor that was included in Unix, much more sophisticated editors like vi and emacs have replaced it, but it still finds many specialized applications in scripts and automated editing.
Syntaxed [options] [file]
Here, [options] are optional flags to modify the behavior of ed, and [file] is the name of the file that you want to edit (also optional).
Basic ed Command ExampleThe easiest way to enter the ed text editor is with the bare command "ed" in the terminal, no options, and no filename to specify it with. This creates a new, empty buffer for you to write in.
edTerminal displaying ed command prompt Key Options and Usage Common Options
Option
Description
-p string
Use string as the prompt instead of the default period (.)
-s
Suppression diagnostics (schticky mode)
-v
Use verbose mode, print line numbers and error messages
-G
Enable compatibility mode with the POSIX ed utility
Basic ed CommandsLet's walk through an example of fully interacting with ed to compose and modify a simple text file:
Step : 1. Launch ed:edStep : 2. Type a few lines, entering insert mode along the way:
aStep : 3. Print all lines:
This is line 1
This is line 2
This is line 3
.
,pStep : 4. Save the file:
w example.txtStep : 5. Exit ed:
qTerminal output with ed command sequence Interacting with a Data File
Let's imagine we are to use ed to make some quick edit on a CSV file named "users.csv" containing user data.
ed users.csv
,p
1,$s/John/Jonathan/g
w
q
This will:
Compared to more modern text editors, the ed editor is certainly ancient, but it's still a handy utility for rapid edits where large files are involved, or in tightly-constrained resources systems, such as scripts. Its line-based interface and limited command set make it perfect for automated text processing tasks. As a Linux user learns the basics of the ed editor, he can add yet another great tool to his arsenal.
Why would someone use the ed editor when they could use more modern ones?How does ed differ from other text editors like vi or nano?ed is useful for quick edits, especially in scripts or on systems with limited resources. Its simplicity and consistency make it ideal for automated text processing tasks.
Can ed be used for large files?ed is a line editor, not a full-screen editor. It has a minimal interface and uses a command-based approach, unlike vi or nano which are more interactive and visual.
Can ed be used in shell scripts for automated text processing?Yes, ed can be efficient for large files as it only loads the parts of the file you're working on, making it memory-efficient for targeted changes in big files.
Is there a modern use case for ed where it makes more sense than to choose another text editor?Absolutely. ed's predictable behavior and ability to take commands through standard input make it well-suited for use in shell scripts for automated text processing tasks.
Yes, ed can be preferable in scenarios like system recovery, embedded systems with limited resources, automated log processing, and maintaining legacy systems that rely on ed's specific behavior.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4