How the shell script modifies lines in the text before matching rows

Source: Internet
Author: User

Original documents, welcome to read, Forbidden reprint.

In the example, the "yes" in the previous line of the finish is changed to "yes"
One way to do this is to use Sed+awk together.

[Email protected]:~$CatA.txtline0is yesline1is yesline2is yesline3is Yesfinish linethis lines is Nothis line is no#//use awk to find a matching line number to work out the row to modify [email protected]:~$awk '/finish/{print NR-1}'a.txt4 #//Use sed to modify this line [email protected]:~$sed "4 s/yes/yes/"A.txtline0is yesline1is yesline2is yesline3is YES-Finish linethis line was Nothis line is no

What is the practical use of this? For example, I need to do this when I have two lines of code before the exit of a startup script.

Original documents, welcome to read, Forbidden reprint.

How the shell script modifies lines in the text before matching rows

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.