Created
June 28, 2016 18:46
-
-
Save clbarnes/75f8750b56a7aace8157b730b65d876b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import csv | |
| FILE_EXT = '.dat' | |
| SEARCH_TERMS = ('one line to search for \n', 'another line to search for\n') | |
| file_list = [f for f in os.listdir() if f.endswith(FILE_EXT)] | |
| output = [['file name', 'search term 1 exists', 'search term 2 exists']] | |
| for fname in sorted(file_list): | |
| with open(fname) as f: | |
| lines = f.readlines() | |
| output.append([filename] + [term in lines for term in SEARCH_TERMS]) | |
| with open('results.csv', 'w') as f: | |
| writer = csv.writer(f) | |
| writer.writerows(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment