gpt4 book ai didi

linux - grep 选择行

转载 作者:太空宇宙 更新时间:2023-11-04 04:21:55 25 4
gpt4 key购买 nike

我想从日志文件中选择最近7天的记录也包含“OK LOGIN”

 Sat Sep  2 03:32:13 2012 [pid 12461] CONNECT: Client "66.249.68.236"
Sat Sep 2 03:32:13 2012 [pid 12460] [ftp] OK LOGIN: Client "66.249.68.236", anon password "gxxglxxxxt@google.com"
Sat Sep 2 03:32:14 2012 [pid 12462] [ftp] OK DOWNLOAD: Client "66.249.68.236", "/pub/10.5524/100001_101000/100022/readme.txt", 451 bytes, 1.39Kbyte/sec
Sat Sep 2 03:32:22 2012 [pid 12677] CONNECT: Client "66.249.68.236"
Sat Sep 2 03:32:23 2012 [pid 12676] [ftp] OK LOGIN: Client "66.249.68.236", anon password "xxxxxbot@google.com"

我使用这个命令,但它不起作用以及如何编写如果我想要 date= [当前日期 - 7 天]

 cat vsftp.log | grep 'OK LOGIN' |egrep "Sep [1-6]"

最佳答案

你可以use sed to select range of lines and generate the regex using date :

#!/bin/bash

function md()
{
date +'%b %e' --date "$@"
}

start=`md 'last week'`
end=`md 'now'`
grep 'OK LOGIN' | sed -n "/$start/,/$end/p"

每天应该至少有一次登录。正则表达式是允许的,可能存在误报。

关于linux - grep 选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12292928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com