# this match requires the characters to match exactly search_str = input('grep: ') filename = input('in : ') textfile = open(filename, 'r') line_num = 0 for line in textfile: line_str = line.strip() line_num += 1 if line_str.find(search_str) >= 0: print(line_num, line_str) textfile.close()