Go Line Filters
A line filter is a common type of program that reads input from stdin, processes it line-by-line, and then prints a result to stdout. Examples include grep or sed.
Basic Example: Uppercase Filter
This program reads text from stdin, converts it to uppercase, and prints it.
How to use it
You can use the pipe (|) operator in your terminal to feed data into your Go program:
Common Filter Ideas
- Grep: Only print lines that contain a specific word.
- Line Counter: Add a number to the start of every line.
- Search and Replace: Replace every occurrence of "foo" with "bar".
- Log Parser: Extract only the timestamp and error message from a log file.
Why use Line Filters?
- Memory Efficiency: By processing data line-by-line, your program can handle files that are much larger than the available RAM.
- Composability: You can chain multiple small filter programs together to solve complex tasks.