Get line number while using grep
grep -n SEARCHTERM file1 file2 …
grep -n SEARCHTERM file1 file2 …
In Go 1.1 and newer the most simple way to do this is with a bufio.Scanner. Here is a simple example that reads lines from a file: package main import ( “bufio” “fmt” “log” “os” ) func main() { file, err := os.Open(“/path/to/file.txt”) if err != nil { log.Fatal(err) } defer file.Close() scanner := bufio.NewScanner(file) … Read more