Linux Basics

You are currently auditing this course.
89 / 107

Pipes - Introduction

If we want to send the output of one program to another, we can use the 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

Note- wc command also counts new line (\n ) character.

Now, if we want to count the 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 the above command to succeed in the assessment.


Loading comments...