ibeautiful
像这样的东西?package mainimport ( "bufio" "bytes" "fmt" "os")func Find(fname string, from, to int, needle []byte) (bool, error) { f, err := os.Open(fname) if err != nil { return false, err } defer f.Close() n := 0 scanner := bufio.NewScanner(f) for scanner.Scan() { n++ if n < from { continue } if n > to { break } if bytes.Index(scanner.Bytes(), needle) >= 0 { return true, nil } } return false, scanner.Err()}func main() { found, err := Find("test.file", 18, 27, []byte("Hello World")) fmt.Println(found, err)}