How about something like func grep(pat []byte, r io.Reader, w io.Writer) error { scanner := bufio.NewScanner(r) for scanner.Scan() { if (bytes.Contains(scanner.Bytes(), pat)) { w.Write(scanner.Bytes()) } }
return scanner.Err() } and for extra speed, just allocate a bigger buffer to the scanner... On Saturday, 7 May 2022 at 21:46:33 UTC+1 Jan Mercl wrote: > On Sat, May 7, 2022 at 10:24 PM Constantine Vassilev <ths...@gmail.com> > wrote: > > > I need to write a program that reads STDIN and should output every line > that contains a search word "test" to STDOUT. > > Piping the data through grep(1) would be my first option. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a5ab9f72-edd5-44ad-b30e-60aeed57823dn%40googlegroups.com.