Created
January 24, 2017 15:19
-
-
Save cipepser/a7b27f35e5b111f979022b367ef696c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"bufio" | |
"log" | |
"io" | |
) | |
func main() { | |
var count int | |
if len(os.Args) != 2 { | |
log.Fatal("Please input filename as a first standard input.") | |
} else { | |
fmt.Printf(">> read file: %s\n", os.Args[1]) | |
fp, err := os.Open(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer fp.Close() | |
reader := bufio.NewReaderSize(fp, 4096) | |
for { | |
_, _, err := reader.ReadLine() | |
if err == io.EOF { | |
break | |
} else if err != nil { | |
log.Fatal(err) | |
} | |
count++ | |
} | |
fmt.Println(count) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment