Mercurial > mercurial > hgweb_golang.cgi
view src/uq.go @ 23:a3c8d0b20a60
ut: add file server & web server.
author | pyon@macmini |
---|---|
date | Mon, 09 Jul 2018 20:56:13 +0900 |
parents | de451fa0c9cd |
children |
line wrap: on
line source
package main import ( "bufio" "flag" "fmt" "os" ) func main() { var c = flag.Bool( "c", false, "count each items" ) var l = flag.Bool( "l", false, "count items") flag.Parse() files := flag.Args() count := make( map[string] int ) var lines []string // Input if len( files ) == 0 { input := bufio.NewScanner( os.Stdin ) for input.Scan() { count[input.Text()]++ lines = append( lines, input.Text() ) } } else { for _, arg := range files { f, err := os.Open( arg ) if err != nil { fmt.Fprintf( os.Stderr, "uq : %v\n", err ) continue } input := bufio.NewScanner( f ) for input.Scan() { count[input.Text()]++ lines = append( lines, input.Text() ) } f.Close() } } // Output if *l { fmt.Println( len(lines), "->", len(count) ) return } done := make( map[string] int ) for _, line := range lines { if done[line] == 0 { if *c { fmt.Printf( "%s,\t%d\n", line, count[line] ) } else { fmt.Println( line ) } } done[line]++ } }