Skip to content

Instantly share code, notes, and snippets.

@johncoder
Last active June 27, 2018 14:44
Show Gist options
  • Save johncoder/74bfce2288114b8a40dc to your computer and use it in GitHub Desktop.
Save johncoder/74bfce2288114b8a40dc to your computer and use it in GitHub Desktop.
A program that observes input and reacts when it finds a specific value.

This is a simple program that watches stdin and echos to stdout. When it finds input like bleep it echos preemptive bloop.

go build
cat input.txt | ./bleep

Sample output:

➜  bleep  cat input.txt | ./bleep
testing
one
two
three
preemptive bloop
bleep
bloop
done!
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
if line == "bleep\n" {
fmt.Println("preemptive bloop");
}
fmt.Print(line);
}
}
testing
one
two
three
bleep
bloop
done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment