Sed: how to limit the modification range?

Source: Internet
Author: User

Sometimes, when we modify the configuration file, we need to specify certain regions where sed cannot be modified. For example:

Sed-e '2017 S/okay now // G'-e '2017, $ S/okay now // G' config_file

We noticed that rows 101st to 199th were ignored by sed.

We also note that here S // is used to replace the expression. If you use the delete statement, for example, // D, it must be placed in the braces ." // A \ "add is the same! For example:

Sed-e '2017 {/okay now/d} '-e '2017, $ {/okay now/d}' config_file


2. If we do not know the exact row number, but only the keyword, we can use "/keyword/" to replace the row number, for example:

Sed-e '^,/Okay No/{/okay now/d}-e' ^,/Okay No/{/Okay No/A \ Okay now} 'config_file

This expression deletes okay now from the beginning to okay no, and adds okay now again after Okay No.

Sed: how to limit the modification range?

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.