updated format to look like gopl.io format

This commit is contained in:
dm
2015-12-03 19:32:40 -08:00
parent 4fd6aaaeff
commit 2cf179e6a4
2 changed files with 88 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
counts := make(map[string]int)
file := os.Args[1:]
if len(file) == 0 {
countLines(os.Stdin, counts)
} else {
for _, i := range file {
f, err := os.Open(i)
if err != nil {
log.Print(err)
}
countLines(f, counts)
f.Close()
}
}
for lines, n := range counts {
if n > 1 {
fmt.Printf("%d\t%s\n", n, lines)
}
}
}
func countLines(f *os.File, counts map[string]int) {
input := bufio.NewScanner(f)
for input.Scan() {
counts[input.Text()]++
}
}