|
output the occurence number in sed or grep results in every regex match
i have a large plain text kml file (example below) :
<Polygon>
<coordinates>
120,14
121,14
...
...
...
121,13
</coordinates>
</Polygon>
<Polygon>
<coordinates>
130,15
131,15
...
...
...
131,14
</coordinates>
</Polygon>
where i need to replace every line containing <Polygon> with
<!-- n --><Polygon>
where n is the nth occurence of the match in the entire file.
search results i have encountered teach only how to replace the (say) fifth occurence of a match in the file. what i need is to display the nth occurence everytime there is a match.
is this possible? the file is very large.
any help, suggestion, recommendation welcome. thanks.
|