init
This commit is contained in:
commit
f7443bbab9
30 changed files with 271 additions and 0 deletions
33
dup2/dup2.go
Normal file
33
dup2/dup2.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
counts := make(map[string]int)
|
||||
files := os.Args[1:]
|
||||
if len(files) == 0 {
|
||||
countLines(os.Stdin, counts)
|
||||
} else {
|
||||
for _, arg := range files {
|
||||
f, err := os.Open(arg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "dup2: %v\n", err)
|
||||
continue
|
||||
}
|
||||
countLines(f, counts)
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func countLines(f *os.File, counts map[string]int) {
|
||||
input := bufio.NewScanner(f)
|
||||
for input.Scan() {
|
||||
counts[input.Text()]++
|
||||
}
|
||||
}
|
0
dup2/dup2.go~
Normal file
0
dup2/dup2.go~
Normal file
4
dup2/test.txt
Normal file
4
dup2/test.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
test
|
||||
test
|
||||
test
|
||||
test
|
Reference in a new issue