# matches regardless of upper- or lowercase search_str = input('grep: ').lower() # make this lowercase filename = input('in : ') textfile = open(filename, 'r') line_num = 0 for line in textfile: line_str = line.strip() line_num += 1 # search for string in lowercase version of line if line_str.lower().find(search_str) >= 0: # but print the original version of line print(line_num, line_str) textfile.close()