Well, basically use output-redirection
my command|grep stackoverflow > file #writes output to <file>
my command|grep stackoverflow >> file #appends <file> with output
my command|grep stackoverflow|tee file #writes output to <file> and still prints to stdout
my command|grep stackoverflow|tee -a file #appends <file> with output and still prints to stdout
The pipe takes everything from stdout and gives it as input to the command that follows. So:
echo "this is a text" # prints "this is a text"
ls # prints the contents of the current directory
grep will now try to find a matching regular expression in the input it gets.
echo "my command" | grep stackoverflow #will find no matching line.
echo "my command" | grep command #will find a matching line.
I guess "my command" stands for a command, not for the message "my command"