I need to comment a set of line which has similar pattern with a unique value on it.
example
a {
1
2 one
3
}
a {
1
2 two
3
}
In the above example I need to comment the entire block. base on the unique value "two" like this.
a {
1
2 one
3
}
#a {
#1
#2 two
#3
#}
The above I'm able to get the block with index line but unable to do a inplace edit or replace. I'm using python2 code:
line = open('file').readlines()
index = line.index('two\n')
abline = int(index)-2
beline = int(abline)+5
for linei in range(abline,beline+1):
nline = '%s%s' % ("##",line[linei].strip())
print(nline)