How to Use the Pipe Character
The pipe character is a Unix command that allows the output of one program to be piped into another program as input. It allows you to chain together multiple applications using a very simple semantic. The pipe character is simply "|" (ignore the quotes). Adding pipes to code does not significantly increase its complexity or decrease its readability. If you are new to Unix (or Linux), learning about pipes should be your first priority.
Instructions
-
-
1
Open a command shell. This is accomplished by pressing the command shell icon that may be placed anywhere inside the Linux system. In Ubuntu Linux, you can find it under "Accessories/Command Prompt." Under versions of Linux running KDE, you may find it under "Applications/Konsole." If you are a true Unix nerd, you don't use a fancy graphical user interface and the computer boots directly to the command shell.
-
2
Select a small text file with several words in it. If you do not have such a text file, quickly open a text editor and fill it with three to five words. Save the file as "pipeExample.txt."
-
-
3
Type the following into the command prompt:
cat pipeExample.txt | wc
-
4
Press the enter key to execute this command. What this does is list the contents of the file "pipeExample" using the "cat" command, and then it pipes the output to another program, in this case "wc", which counts the words of whatever it is submitted. The program output may look something like this:
5 4 2 2 1
-
1