Description
If there are nothing except blanks, newline characters between
PAT1 and PAT2,
reduces them to just one newline character.
|
| Raw Input
|
| Desired Output
| === PAT1
PAT2 ===
PAT 1 ...
...
PAT 2 === PAT1
PAT2 === PAT1 ...
...
... PAT2 --- PAT1
PAT2
---
|
| === PAT1
PAT2 ===
PAT 1 ...
...
PAT 2 === PAT1
PAT2 === PAT1 ...
...
... PAT2 --- PAT1
PAT2
---
|
|
Script and Comments
Script1 [ 1] :top
[ 2] /PAT1/!b
[ 3] :loop
[ 4] $q
[ 5] N
[ 6] /\n *$/b loop
[ 7] /\n *PAT2[^\n]*$/b matched
[ 8] h
[ 9] s/\n[^\n]*$//p
[10] x
[11] s/^.*\n//
[12] b top
[13] :matched
[14] s/PAT1( *\n *)*PAT2/PAT1\nPAT2/
[15] P
[16] D
| |
Script2 [ 1] /PAT1/!b
[ 2] :loop
[ 3] $q
[ 4] N
[ 5] /\n *$/b loop
[ 6] /\n *PAT2[^\n]*$/b matched
[ 7] h
[ 8] s/\n[^\n]*$//p
[ 9] x
[10] s/^.*\n/\n/
[11] D
[12] :matched
[13] s/PAT1( *\n *)*PAT2/PAT1\nPAT2/
[14] P
[15] D
| |