Created
December 13, 2016 13:15
-
-
Save tatesuke/e600211f57dfb8fe6d3ce0032b33a72c to your computer and use it in GitHub Desktop.
ログファイルを日時でフィルタ
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
| def ARG_SDF = new java.text.SimpleDateFormat("yyyy-MMdd-HHmm-ss", java.util.Locale.US); | |
| def LOG_SDF = new java.text.SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z", java.util.Locale.US); | |
| def logFile = new File(args[0]); | |
| def startTime = ARG_SDF.parse(args[1]); | |
| def endTime = ARG_SDF.parse(args[2]); | |
| def scanner = new java.util.Scanner(logFile); | |
| while (scanner.hasNextLine()) { | |
| def line = scanner.nextLine(); | |
| def dateStr = line.split("\\[|\\]")[1]; | |
| def date = LOG_SDF.parse(dateStr); | |
| if (date.getTime() < startTime.getTime()) { | |
| continue; | |
| } | |
| if (endTime.getTime() < date.getTime()) { | |
| break; | |
| } | |
| println line; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment