Pipe and grep is a very powerful tool of 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 tool.
What is a Pipe
pipe is a way by which we can use two or more commands simultaneously. where output of one command work as input of another command. We denotes with | symbol. We can create 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 number of lines, number of words, number of bytes.
touch fruits_list cat > fruits_list apple banana grape blueberry #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 particular information from text file. like we have create a file in which we have list of fruits and we want to search particular fruit. Let us understand this with an example.
cat fruits_list | grep apple apple,
Some basic example of grep
show lines containing xyz in myFile
grep 'apple' fruits_list apple,
Show lines containing msg in all files ending in html in current dir top level files
grep 'msg' *html