Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.