Shell command usage and common use cases under Linux: SED

Source: Internet
Author: User

Click to view the original blog.

sedis the abbreviation for Stream editor, which is a non-interactive stream editor for filtering or converting text.
Not to be continued ...

Profile

Sed Options ... Script [Input File ...]

Describe

sedThe editor is called the Stream editor, which is the opposite of the normal interactive text editor. In an interactive text editor, such as VIM, you can use keyboard commands to interactively insert, delete, or replace text in your data. The stream editor edits the data flow based on a pre-supplied set of rules before the editor processes the data.
sedThe editor can process data in the data flow according to commands, which are either entered from the command line or stored in a command text file. The SED editor performs the following actions.

(1) reads one row of data from the input at a time.

(2) match the data according to the provided editor commands.

(3) Follow the commands to modify the data in the stream.

(4) Output the new data to the STDOUT. After the flow editor matches all the commands to a row of data, it reads the next row of data and repeats the process. When the stream editor finishes processing all the data rows in the stream, it terminates. Because the commands are given sequentially by line, the SED editor can complete the editing operation by simply processing the data stream over and over.
This makes the SED editor much faster than the interactive editor, and you can quickly complete automatic changes to the data.

Understand

This command is somewhat complex and complex, and requires a gradual digestion as it is powerful.

Common use Cases

The instance replaces all "Hello" in the Input.txt file with "world" and outputs it to output.txt.

sed ‘s/hello/world/‘ input.txt > output.txt

This is probably the most commonly used example (at least in my experience of working for so many years), sed the commands used here s . If you want to export to the original file, use -i parameters.

sed -i ‘s/hello/world/‘ input.txt

This will behave differently under Mac, refer to: 49495885.

Reference: Https://www.gnu.org/software/sed/manual/sed.html.

Shell command usage and common use cases under Linux: SED

Related Article

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.