Description
In the following example, we want to replace the last word with
six dashes.
|
| Raw Input
|
| Desired Output
| word_1 word_2 word_3
more data...
word_4 word_5
more data...
word_6 word_7
word_8
more data...
word_9 final word_10
|
| word_1 word_2 word_3
more data...
word_4 word_5
more data...
word_6 word_7
word_8
more data...
word_9 final ------_10
|
|
Script and Comments
Script1 [ 1] :0
[ 2] /word/!b
[ 3] :1
[ 4] $!N
[ 5] /\n.*word/{
[ 6] h
[ 7] s/\n[^\n]*$//p
[ 8] g
[ 9] s/^.*\n//
[10] }
[11] $!b 1
[12] s/^(.*)word/\1------/
| |