# tail -f a.txt |grep ‘python‘ #tail -f a.txt import time def tail(conf): with open(conf,encoding=‘utf-8‘) as f: f.seek(0,2) while True: f1 = f.readline().strip() if f1: yield f1 else: time.sleep(0.5) # t = tail(‘a.txt‘) # print(next(t)) # for line in t: # print(line) # grep ‘python‘ def grep(kewords,lines): for line in lines: if kewords in line: yield line g = grep(‘python‘,tail(‘a.txt‘)) for i in g: print(i)
tail -f a.txt | grep 'python'
时间: 2024-10-23 10:18:12