How to use the Linux ed command

Source: Internet
Author: User

Ed is the simplest text editing program in Linux. It can only edit one row at a time rather than the full screen mode.

The ed command is not a common command. Generally, the vi command is used. However, the ed text editor is useful for editing large files or text editing in shell scripts.

Syntax

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

Parameters:

  • -G or -- traditional provides the back-compatible function.
  • -P <string> specifies the prompt character of ed in command mode.
  • -S,-, -- quiet or -- silent does not perform the check function when the file is enabled.
  • -- Help: displays help.
  • -- Version: displays the version information.

Instance

The following is a complete Linux ed instance resolution:

$ Ed <-activate ed command

A <-tell ed that I want to edit the new file

My name is Titan. <-enter the content of the first line.

And I love Perl very much. <-enter the second line of content

. <-Return the command line status of ed

I <-tell ed that 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 the command line status of ed

C <-tell ed that I want to replace the last input line

I am 24 years old. <-replace "I am 24." with "I am 24 years old." (note: The Last input is replaced here)

. <-Return the command line status of ed

W readme. text <-name the file "readme. text" and save it. (Note: If you are editing an existing file, you only need to enter w)

Q <-exit the ed editor completely

The content of this file is:

$ Cat readme. text

My name is Titan.

I am 24 years old.

And I love Perl vrey much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.