Description
In the example, we want to replace every occurrence of word with
six dashes except the last three occurrences of a file.
|
| Raw Input
|
| Desired Output
| word_1
much more data...
word_2 word_3 word_4
much more data...
word_5
word_6 word_7
much more data...
word_8 final word_9
|
| ------_1
much more data...
------_2 ------_3 ------_4
much more data...
------_5
------_6 word_7
much more data...
word_8 final word_9
|
|
Script and Comments
Script1 [ 1] /word/!b
[ 2] :0
[ 3] /(word.*){4}/!{
[ 4] $!N
[ 5] $!b 0
[ 6] }
[ 7] :1
[ 8] s/word((.*word){3})/------\1/
[ 9] t 1
[10] $q
[11] :2
[12] /^[^\n]*word/!{
[13] P
[14] s/^[^\n]*\n//
[15] b 2
[16] }
[17] b 0
| |