Created
June 16, 2017 09:13
-
-
Save ChristianKniep/d0671beca68980ba96bb1302fc9931b9 to your computer and use it in GitHub Desktop.
Parse DockerBench
This file contains 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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"regexp" | |
"os" | |
) | |
func getParams(regEx, url string) (paramsMap map[string]string) { | |
var compRegEx = regexp.MustCompile(regEx) | |
match := compRegEx.FindStringSubmatch(url) | |
paramsMap = make(map[string]string) | |
for i, name := range compRegEx.SubexpNames() { | |
if i > 0 && i <= len(match) { | |
paramsMap[name] = match[i] | |
} | |
} | |
return | |
} | |
func main() { | |
file, err := os.Open(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
line := scanner.Text() | |
params := getParams(`\[(?P<LEVEL>\w+)\]\s+(?P<NOM>[0-9\.]+)?\s+(?P<SPLIT>[\*\-])\s+(?P<MSG>.*)`, line) | |
if params["LEVEL"] != "" { | |
fmt.Printf("%s;%s;%s;%s\n", params["LEVEL"], params["NOM"], params["SPLIT"], params["MSG"]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment