Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created June 28, 2016 18:46
Show Gist options
  • Select an option

  • Save clbarnes/75f8750b56a7aace8157b730b65d876b to your computer and use it in GitHub Desktop.

Select an option

Save clbarnes/75f8750b56a7aace8157b730b65d876b to your computer and use it in GitHub Desktop.
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