简体   繁体   中英

How can i separate out date and time field from apache access logs?

XX.XX.XX.XXX - - [22/Sep/2015:00:59:54 +0000] "POST /zabbix/jsrpc.php?output=json-rpc HTTP/1.1" 200 66 "http://XXX.XX.XX.XXX/zabbix/dashboard.php?sid=ca62d327b6afb561" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"

This is my apache access log. I want to parse this logs and want only date filed (not the time stamp) . So How can i get 22/Sep/2015 this output ?

Using grep -oP (PCRE):

grep -oP '(?<=\[)\d+/[A-Z][a-z]+/\d+' access.log
22/Sep/2015

If your grep doesn't support -P then use sed :

sed -r 's~.*\[([0-9]+/[A-Z][a-z]+/[0-9]+).*~\1~' access.log
22/Sep/2015

Or on OSX:

sed -E 's~.*\[([0-9]+/[A-Z][a-z]+/[0-9]+).*~\1~' access.log
22/Sep/2015

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM