$ cat fred barney | sort | ./your_program | grep something | lpr
# This line says the command should print out all of the lines of the file fred, followed by all the lines of the file barney.
# That output is then the input of the sort command, which sorts those lines and passes them to your_program.
# Then, your_program sends the data to grep, which discards certain lines in the data, sending the others to the lpr command, which should print everything that it gets on a printer.