miller/experiments/line-parser/scanner.go
John Kerl 728034d184
Fix read of files which lack final newline (#683)
* Fix regression-test cases using redirects

* Fix more cases

* Update CASEDIR handling on Windows

* Regression-test fixes

* More regtest iteration

* Fix read of files which lack final newline
2021-10-04 23:05:57 -04:00

26 lines
438 B
Go

package main
import (
"bufio"
"fmt"
"os"
)
func main() {
filename := os.Args[1]
handle, err := os.Open(filename)
if err != nil {
fmt.Println("OERR", err)
os.Exit(1)
}
defer handle.Close()
scanner := bufio.NewScanner(handle)
for scanner.Scan() {
fmt.Println(scanner.Text()) // Println will add back the final '\n'
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
}