3 回答
TA贡献1831条经验 获得超4个赞
awk
.
awk -vDate=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 > Date {print Date, $0}' access_log
Note the -d'now-2 hours'
[10/Oct/2011:08:55:23
awk -vDate=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 > Date {print $1}' | sort |uniq -c |sort -n | tail
awk -vDate=`date -d'now-4 hours' +[%d/%b/%Y:%H:%M:%S` -vDate2=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 > Date && $4 < Date2 {print Date, Date2, $4} access_log'
TA贡献1951条经验 获得超3个赞
因为这是 共同 Perl 任务
#!/usr/bin/perl -ws# This script parse logfiles for a specific period of timesub usage { printf "Usage: %s -s=<start time> [-e=<end time>] <logfile>\n"; die $_[0] if $_[0]; exit 0;}use Date::Parse;usage "No start time submited" unless $s;my $startim=str2time($s) or die;my $endtim=str2time($e) if $e;$endtim=time() unless $e;usage "Logfile not submited" unless $ARGV[0];open my $in, "<" . $ARGV[0] or usage "Can't open '$ARGV[0]' for reading";$_=<$in>;exit unless $_; # empty file# Determining regular expression, depending on log formatmy $logre=qr{^(\S{3}\s+\d{1,2}\s+(\d{2}:){2}\d+)};$logre=qr{^[^\[]*\[(\d+/\S+/(\d+:){3}\d+\s\+\d+)\]} unless /$logre/;while (<$in>) { /$logre/ && do { my $ltim=str2time($1); print if $endtim >= $ltim && $ltim >= $startim; };};
./timelapsinlog.pl -s=09:18 -e=09:24 /path/to/logfile
./timelapsinlog.pl -s='2017/01/23 09:18:12' /path/to/logfile
january 23th, 9h18'12"
-s
-s=09:18
$s
09:18
=
诺塔:
^(\S{3}\s+\d{1,2}\s+(\d{2}:){2}\d+) # ^Jan 1 01:23:45^[^\[]*\[(\d+/\S+/(\d+:){3}\d+\s\+\d+)\] # ^... [01/Jan/2017:01:23:45 +0000]
TA贡献1805条经验 获得超9个赞
awk: invalid -v option
cat <FILE_NAME> | awk '$4 >= "[04/Jul/2017:07:00:00" && $4 < "[04/Jul/2017:08:00:00"' | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20
- 3 回答
- 0 关注
- 380 浏览
添加回答
举报