Something like this:
import re
import os # You can go without is if you have other means to get your filepath
i = 1
matches = []
target = raw_input("Please type string to match\n")
with open(os.getenv("SOME_PATH") + "/myfile.txt") as fic: # open("myfile.txt") if in your current directory
for line in fic:
if re.search(target, line):
print "Found at line {}".format(i)
matches.append(i)
i = i +1
if not len(matches):
raise Exception, "target not found"
By doing this, you can input a regular expression and it should work (i.e. if you input "p.zza" or "^p.*", it will work.). The list matches
will contain all indices of lines that match the input pattern.