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