# FILE: grep.py # AUTHOR: Eugene Wallingford # DATE: 2014/10/16 # COMMENT: Search for occurrences of a string in a file. Match # strings regardless of upper- or lowercase. search_str = input('grep: ').lower() # Make the search string 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 a lowercase version of the line... if line_str.lower().find(search_str) >= 0: # ... but print the original version of the line. print(line_num, line_str) textfile.close()