1
0
gotour-notes/stdin-or-argv/go.go
2012-09-07 11:32:18 -06:00

30 lines
459 B
Go

package main
import (
"fmt"
// "io"
"io/ioutil"
"log"
// "bufio"
"os"
"strings"
)
var usage = "usage: splitter [file]"
func main() {
var of *os.File
var err error
if len(os.Args) == 2 {
filename := os.Args[1]
of, err = os.Open(filename)
if err != nil {
log.Fatal(err)
}
} else {
of = os.Stdin
}
b, err := ioutil.ReadAll(of)
fmt.Printf("%v\n", strings.Fields(string(b)))
}