Description
In the example, we want to keep the first three occurrences of word intact, and replace every other one with six dashes.
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
word_1 
much more data...
word_2 word_3 ------_4
much more data...
------_5 ------_6
------_7
much more data...
------_8 final ------_9
Script and Comments
Script1
[ 1] :0
[ 2] /(word.*){3}/!{
[ 3] $!N
[ 4] $!b 0
[ 5] }
[ 6] :1
[ 7] /(word.*){4}/{
[ 8] s/^(.*)word/\1------/
[ 9] t 1
[10] }
[11] :2
[12] n
[13] s/word/------/g
[14] b 2
Comments
  1. The `-r' option of GNU sed must be used to make sed interpret REs as EREs.
  2. The Pattern Space is abbreviated to PS.
  3. Steps [1] thru [5] constitute a loop which will repeat till there are at least 3 occurrences of word in PS or the end of the datafile is reached.
  4. If the fourth or further occurrences are in the same line with the third one, the PS now will have four or more occurrences of word.
    If this is the case, all but the first three occurrences in PS must be replaced, which is done via Steps [6] thru [10],
    where each execution of Step [7] replaces the last occurrence in PS.