Description
- The contents between 'BEGIN' and its matching 'END' may span several lines.
- Besides, there may exist several BEGIN-END pairs in a line.
- The following script does not take nested pairs into consideration.
|
| Raw Input
| word-A BEGIN word-B
word-C word-D
word-E END word-F
word-G
word-H BEGIN word-I END word-J BEGIN word-K
word-L word-M
END word-N
word-O
|
|
| Desired Output
| word-B
word-C word-D
word-E
word-I
word-K
word-L word-M
|
|
Script and Comments
Script1 [ 1] /BEGIN/!d
[ 2] s/BEGIN/\n/
[ 3] s/^.*\n//
[ 4] /END/{
[ 5] s/END/\n/
[ 6] P
[ 7] D
[ 8] }
[ 9] :loop
[10] H
[11] $d
[12] N
[13] s/^.*\n//
[14] /END/!b loop
[15] s/END/\n/
[16] H
[17] x
[18] s/^\n\(.*\)\n.*/\1/
[19] p
[20] s/^.*//
[21] x
[22] D
| |