I have written a Python Script to find out lines containing a particular script from each of the files within a directory. It works fine if i make this script run in the directory having those files.
#!/usr/bin/env python
import os
def searchthis(location, searchterm):
for fname in os.listdir(location):
fullpath = os.path.join(location, fname)
for line in file(fullpath):
if searchterm in line:
print line
searchthis(os.getcwd(), "mystring")
Is there any way I could do this with os.walk and search for recursively in each of the files present in all the directories as well as subdirectories.
1 Answer