How to replace an atypical pattern in a text file using sed

view story

http://askubuntu.com – I have an MRTG configuration file containing some lines starting with the word "Target". Now in such lines there is a pattern starting with the character "#" and end with character ":". A sample line could look like these (note two types but start/end markers still same): Target[]: #Gi1/1:[email protected]:::::2 Target[]: #Gi1/31:[email protected]:::::2 What I need is for sed to find these lines and replace the pattern "#Gix/n:" to "ifInErrors#Gix/n&ifInErrors#Gix/n:", where x=1-9, n=1-48. So the two sample lines shown above would be mod (HowTos)