首页 > 编程语言 > 详细

tail -f a.txt | grep 'python'

时间:2017-05-27 00:22:34      阅读:559      评论:0      收藏:0      [点我收藏+]
# 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'

原文:http://www.cnblogs.com/wangkc/p/6910864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!