Skip to content

Instantly share code, notes, and snippets.

@ChristianKniep
Created June 16, 2017 09:13
Show Gist options
  • Save ChristianKniep/d0671beca68980ba96bb1302fc9931b9 to your computer and use it in GitHub Desktop.
Save ChristianKniep/d0671beca68980ba96bb1302fc9931b9 to your computer and use it in GitHub Desktop.
Parse DockerBench
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