| A line filter is a common type of program that reads
input on stdin, processes it, and then prints some
derived result to stdout. grepandsedare common
line filters. |  | 
        
        
          | Here’s an example line filter in Go that writes a
capitalized version of all input text. You can use this
pattern to write your own Go line filters. |   | 
        
        
          |  | import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
 | 
        
        
          |  |  | 
        
        
          | Wrapping the unbuffered os.Stdinwith a buffered
scanner gives us a convenientScanmethod that
advances the scanner to the next token; which is
the next line in the default scanner. | 	scanner := bufio.NewScanner(os.Stdin)
 | 
        
        
          | Textreturns the current token, here the next line,
from the input.
 |  | 
        
        
          |  | 		ucl := strings.ToUpper(scanner.Text())
 | 
        
        
          | Write out the uppercased line. |  | 
        
        
          | Check for errors during Scan. End of file is
expected and not reported byScanas an error. | 	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "error:", err)
		os.Exit(1)
	}
}
 |