Basic use of pipe and grep command

pipe and grep

Pipe and grep is a very powerful tool of the Linux command line. So before we start Basic use of pipe and grep command we need to understand what is pipe and grep and how to use both tools.

What is a Pipe

pipe is a way by which we can use two or more commands simultaneously. where the output of one command works as an input of another command. We denote with | symbol. We can create a lot of powerful commands with deadly combination with other commands. Let us understand this with an example.

When we use “cat” command then we can view file and wc command will count the number of lines, number of words, number of bytes.

touch fruits_list
cat > fruits_list
#CTRL-D to save and exit
cat fruits_list | wc

The ‘grep’ command

grep is the most important command. You should master it. suppose that we want to search for particular information from the text file. like we have created a file in which we have a list of fruits and we want to search particular fruit. Let us understand this with an example.

cat fruits_list | grep apple

Some basic example of grep

show lines containing xyz in myFile

grep 'apple' fruits_list

Show lines containing msg in all files ending in html in current dir top level files

grep 'msg' *html

Also Read: Install and remove linux packages, Basic use of ls or list command

You May Also Like

About the Author: Pankaj Bisht