Created
June 6, 2018 01:18
-
-
Save akagisho/b05f29352b217a25623ba960ecf799eb to your computer and use it in GitHub Desktop.
Apache のログの日時を Excel が認識できる形式に変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import re | |
from datetime import datetime | |
for line in sys.stdin: | |
m = re.search('\[(\d{2}/[A-Z][a-z]{2}/\d{4}:\d{2}:\d{2}:\d{2}) .{0,6}\]', line) | |
if m: | |
d = datetime.strptime(m.group(1), '%d/%b/%Y:%H:%M:%S') | |
line = re.sub(r'\[\d{2}/[A-Z][a-z]{2}/\d{4}:\d{2}:\d{2}:\d{2} .{0,6}\]', str(d), line, 1) | |
sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment