Easy Tutorial
❮ Linux Comm Cat Linux Comm Uniq ❯

Linux ed Command

Linux Command Handbook

The Linux ed command is a text editor used for text editing.

ed is the simplest text editor in Linux, capable of editing one line at a time rather than in a full-screen mode.

The ed command is not commonly used; commands like vi are more frequently employed. However, the ed text editor is useful for editing large files or for text editing within shell scripts.

Syntax

ed [-][-Gs][-p<string>][--help][--version][file]

Parameters:

Example

Below is a complete example of using the Linux ed command:

$ ed              <- Activate the ed command 
a                 <- Tell ed I want to edit a new file 
My name is Titan. <- Input the first line 
And I love Perl very much. <- Input the second line 
.                 <- Return to ed's command line mode 
i                 <- Tell ed I want to insert content before the last line 
I am 24.          <- Insert "I am 24." between "My name is Titan." and "And I love Perl very much." 
.                 <- Return to ed's command line mode 
c                 <- Tell ed I want to replace the last input 
I am 24 years old. <- Replace "I am 24." with "I am 24 years old." (Note: This replaces the last input) 
.                 <- Return to ed's command line mode 
w readme.text     <- Name and save the file as "readme.text" (Note: For editing an existing file, simply type w) 
q                 <- Exit the ed editor completely

The content of the file is:

$ cat readme.text 
My name is Titan. 
I am 24 years old. 
And I love Perl very much.

Linux Command Handbook

❮ Linux Comm Cat Linux Comm Uniq ❯