Description
In the following example, we want to replace `change this' with `changed to that' from lines starting from the first one containing `begin' till the last one containing `end'.
Raw Input Desired Output
..... keep this
..... keep this
..... keep this
begin change this
..... change this
end   change this
..... change this
end   change this
..... keep this
..... keep this
..... keep this
..... keep this
..... keep this
begin CHANGED TO THAT
..... CHANGED TO THAT
end   CHANGED TO THAT
..... CHANGED TO THAT
end   CHANGED TO THAT
..... keep this
..... keep this
Script and Comments
Script1
[ 1] /begin/,$!b
[ 2] :loop
[ 3] /end/{
[ 4] s/change this/CHANGED TO THAT/g
[ 5] b
[ 6] }
[ 7] $q
[ 8] N
[ 9] b loop
Comments
  1. The flowchat of this script is as follows:
  2. If there is no line containing `end', nothing will be changed.
Script2
[ 1] /begin/,$!b
[ 2] :loop
[ 3] /end/s/change this/CHANGED TO THAT/g
[ 4] t
[ 5] $q
[ 6] N
[ 7] b loop
Comments
  1. A neat version.