func main() { flagutil.Usage = "[file...]" flag.Parse() paths := flag.Args() if len(paths) == 0 { paths = append(paths, "/dev/stdin") } rd, err := lib.MultiFile(paths...) if err != nil { log.Fatal(err) } defer rd.Close() sc := bufio.NewScanner(rd) for line := 0; *mflag || line < *numlines; line++ { if sc.Scan() { fmt.Println(sc.Text()) } else if sc.Err() == nil { return } else { log.Fatal(sc.Err()) } } }
func Read(names []string) []string { // Create a single stream consisting of all the files. buf := make([]string, 0) rd, err := lib.MultiFile(names...) if err != nil { log.Fatal(err) } defer rd.Close() // Read that stream into a slice of strings. sc := bufio.NewScanner(rd) for sc.Scan() { buf = append(buf, sc.Text()) } if sc.Err() != nil { log.Fatal(err) } return buf }