Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created November 10, 2017 09:22
Show Gist options
  • Save meeDamian/bd2d8b45c0671487cd630c1bbd06df03 to your computer and use it in GitHub Desktop.
Save meeDamian/bd2d8b45c0671487cd630c1bbd06df03 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
)
var (
path = flag.String("path", "", "")
debug = flag.Bool("debug", false, "")
)
func init() {
flag.Parse()
if path == nil || len(*path) == 0 {
panic("path to config file is required")
}
}
func main() {
inFile, err := os.Open(*path)
if err != nil {
panic(err)
}
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
stats := make(map[int]int64)
var total int64
for scanner.Scan() {
line := scanner.Text()
addresses := strings.Split(line, ";")[0]
address := addresses
if strings.Contains(addresses, ":") {
address = strings.Split(addresses, ":")[0]
}
length := len(address)
stats[length]++
total++
if !*debug {
continue
}
if total%1e3 == 0 {
if total%1e6 == 0 {
fmt.Printf("\n%dM ", total/1e6)
continue
}
fmt.Print(".")
}
}
for length := 34; length > 0; length-- {
cnt, ok := stats[length]
if !ok {
continue
}
fmt.Printf("\n%d characters:\t%d (%.5f%%)", length, cnt, float64(cnt)/float64(total)*100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment