Linux Basics

71 / 87
Pipes - Introduction

If we want to send the output of one program to another, we can use pipe. A pipe is denoted by "|".

"echo" command prints on the standard output whatever argument is passed to it.

echo "Hi"

"wc" command prints the number of characters, words and lines out of whatever you type on standard input. Start "wc" command, type some text and press Ctrl+d to end the input:

wc
hi
how are you
[CTRL + d]

Output-

        2       4      15

Now, if we want to count number of words, characters in the output of any program, we can pipe the output in the following way:

        echo "Hello, World" | wc

You can also save the results using redirection, in the following way:

        echo "Hello, World" | wc > wc_results

Please execute above command to succeed the assessment.