Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created June 8, 2011 13:29
Show Gist options
  • Save wingyplus/1014412 to your computer and use it in GitHub Desktop.
Save wingyplus/1014412 to your computer and use it in GitHub Desktop.
line count
package main
import (
"io/ioutil"
"fmt"
"os"
)
func main () {
if len (os.Args) > 1 {
// Open file return []byte
fileByte, _ := ioutil.ReadFile (os.Args[1])
// Check len of []byte
lineCount := 0
for i := 0; i < len (fileByte); i++ {
c := fileByte[i]
if c == 10 || i == len (fileByte) - 1 {
lineCount++
}
}
fmt.Println (lineCount)
} else {
fmt.Println ("lc [file]")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment