sed awk grep linux 编程三剑客

今天突发奇想的用sed 搞日志,下面是需求

查询出昨天6点到今天9点的日志,那就用下面这个命令去搞它。

sed -n '/Tue Dec 15 06/,/Wed Dec 16 09/p' vsftpd.log > aaaa.txt

过滤出带“OK” 的行

grep "OK" vsftpd.log aaaa.txt>bbbb.txt

要求取出其中的某一列数字或则是IP 等等,派awk上场

gawk -F: '{print $1,$2}' bbbb.txt> cccc.txt

要求计算出总的数量

python
def subnum():
    a = open("cccc.txt","r",encoding="utf-8").readlines()
    for b in a:  #循环搞定
        c = int(b)+c
    print(c)
subnum()
posted @ 2020-12-16 23:19  浅笑若风  阅读(101)  评论(0编辑  收藏  举报