In the last chapter, > sent output to a file. A pipe, |, sends the output of one command to another command, with no file between them.
grep ERROR shop.log
stdout → stdin
wc -l
stdout
2
text
learner@tidepool:~$ grep ERROR shop.log | wc -l
2grep writes the error lines. The pipe gives them to wc on its standard input. wc has no file name, so it reads standard input and counts the lines.
Build a pipeline one step at a time
You can put many commands in a row. This is a pipeline:
text
learner@tidepool:~$ grep ERROR shop.log | grep -v printer | head -n 3grep ERROR: keep the error lines.grep -v printer: of those, remove the lines about the printer.head -n 3: show only the first three.
Build a pipeline one command at a time. Run the first command and read the output. Then add | next-command.
Save the end of a pipeline
Put > at the end to save the result:
text
learner@tidepool:~$ grep ERROR shop.log | head -n 3 > first-errors.txtOnly standard output goes into the pipe
Standard error does not go into the pipe. Error messages still go to the terminal, so you see them.