How to use the Sed-i command under MAC

Source: Internet
Author: User

Today, in the course of learning Linux, we discovered the SED directive.

First, the full name of the SED is: Stream Editor

There are two forms of calling the SED command:

sed [options] ' command ' file (s)

sed [options]-F scriptfile file (s)

Today, I'll talk about the use of the-i parameter in the SED command.

-I refers to changes in the current text

Specific content can be used in Linux

Mans SED

To view

But if it is the following code, will be error, can not achieve the function I want

Sed-i ' 2,4d ' example.txt

The above code I want to implement delete Example.txt in the 2,3,4 line

Since-I is required and must have a string to back up the source file, and the string will be appended to the source filename to form the backup file name.

So

The correct method is as follows:

Sed-i "" ' 2,4d ' example.txt

So since. We can do what we want.

If you do not want to use the-I parameter, we can also use another method:

Sed ' 2,4d ' example.txt > ANOTHER_EXAMPLE.TXTMV another_example.txt example.txt

OK ~ This is my little harvest. A little harvest a day by a pig

How to use the Sed-i command under MAC

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.