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"
echo my command | grep stackoverflow > ex.txtormy command | grep stackoverflow > ex.txt? The first one will search forstackoverflowin the textmy commandand as that doesn't match nothing will be in ex.txt. – Lucas Mar 16 '16 at 15:36my command | grep stackoverflow > ex.txtand it worked without theecho, why is this? – Jonathan Mar 16 '16 at 15:40echo my commandyou are not runningmy commandso you will not get its output. You are runningechoand telling it to print the text "my command". – Lucas Mar 16 '16 at 15:44