Created
December 2, 2017 15:12
-
-
Save earlwlkr/e06b286e568e48e0dcf424518564bc24 to your computer and use it in GitHub Desktop.
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" | |
"os" | |
"strings" | |
"sort" | |
) | |
func check(e error) { | |
if e != nil { | |
panic(e) | |
} | |
} | |
func main() { | |
count := make(map[string]int) | |
for i := 13; i <= 19; i++ { | |
in, err := os.Open(fmt.Sprintf("./LinkHttpsParseError_2017_10_%d.txt", i)) | |
check(err) | |
defer in.Close() | |
scanner := bufio.NewScanner(in) | |
for scanner.Scan() { | |
text := scanner.Text() | |
subs := strings.Split(text, "/") | |
if len(subs) >= 3 { | |
count[subs[2]]++ | |
} | |
// fmt.Println(count[subs[2]]) | |
} | |
} | |
out, err := os.Create("./out") | |
check(err) | |
defer out.Close() | |
n := map[int][]string{} | |
var a []int | |
for k, v := range count { | |
n[v] = append(n[v], k) | |
} | |
for k := range n { | |
a = append(a, k) | |
} | |
sort.Sort(sort.Reverse(sort.IntSlice(a))) | |
for _, k := range a { | |
for _, s := range n[k] { | |
fmt.Fprintf(os.Stderr, "%s\t%d\n", s, k) | |
fmt.Fprintf(out, "%s\t%d\n", s, k) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment