You can use awk
to do that :
awk -v status_code=200 -v ts_at_hour=15 -v ts_before_hour=15 -v ts_before_min=35 '
{
match($0, /[0-9]+.[0-9]+.[0-9]+.[0-9]+s+[[0-9]{2}/[a-zA-Z]{3}/[0-9]{4}:([0-9]{2}):([0-9]{2}):([0-9]{2})s+[+-][0-9]{4}]s+([0-9]{3})/, items)
if (items[1] == ts_at_hour &&
items[1] <= ts_before_hour &&
items[2] < ts_before_min &&
items[4] == status_code){
print $0
}
}
' data.txt
Set some variables to store your requirements status_code
, ts_at_hour
, ts_before_hour
and ts_before_min
(you can define environment vars to them)
The regex is a match
that focus on 4 groups : hour, minutes, seconds defined by ([0-9]{2})
and status_code at the end ([0-9]{3})
To decompose the regex, you have :
- the IP address
[0-9]+.[0-9]+.[0-9]+.[0-9]+
followed by space s+
(or more)
- the date part which includes hour,minutes and seconds
[[0-9]{2}/[a-zA-Z]{3}/[0-9]{4}:([0-9]{2}):([0-9]{2}):([0-9]{2})s+[+-][0-9]{4}]
(notice the 3 groups between ()
)
- the status code with
([0-9]{3})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…