import os search = "phrase" for fl in os.listdir("./"): if fl[-4:] == ".txt": for line in open(fl,"r"): if search in line: print(line)