I have a file contains 3 blocks
Block1:
a
Block2:
a
Block3:
a
I wanted to search “block1:” a string using python
I have done code for Searching block1 : and a string but it is giving all the a
file = open( "c:\Textfile.txt", "r" ).readlines()
var=raw_input("enter the value")
var1="// Block1:"
for line in file:
if re.search(var1,line,re.IGNORECASE):
print re.search(var,line,re.IGNORECASE)
print "found",line
for line in file:
if re.search(var,line,re.IGNORECASE):
print "value=",line
I am assuming you Textfile is like below:
You can do it like below: