In this way, we learned about the pipe command along with concepts and applications with the help of different examples. The command will process the delimited file_states.txt and will cut the first column having “,” as delimiter and then display the content of the file in a reverse sorting manner. When the above command executes, it will open the file and search the country keyword and will replace it with state text globally in the output fileħ) Use of cat, cut, and echo command to cut out a particular column with delimiterĬat file_states.txt | cut -d ' ' -f 1 | sort -r The above command on execution will open the file and then search for the text “country India,” and by using tee command, it will store in the a.txt afterward will count the total number of lines in the a.txtĦ) Using of cat and sed command to replace a particular text with another text tmp extension in a particular directory and will search for the pattern like “country” and print those lines which contain country keywords in them.ĥ) Using of cat, tee, grep, and wc command in order to read inputs from the user and store in a file to print count of lineĬat a.txt | grep "country India" | tee a.txt | wc -l On executing the command, will list all files and select the file with. type f -name '*.tmp' -exec grep -i 'country' \ The above command will open the file using the cat command and then select the first 8 lines than the last 4 lines from the file.txt, and will printout those lines, which will be common to both commands.Ĥ) Using of ls to discover the list and then print all the lines matching with a particular pattern in the matching file. The above command will first sort the file and print the distinct data sets on the terminal.ģ) Using of head and tail command to print line in a particular range of a file The output of the above two commands will be the same.Ģ) Using of sort and uniq command for sorting a file and print distinct value We can also use the below command sequence to get the result as compared to the I/O redirection operator. The command will not use the disk to connect the standard output of the ls -l command to the standard input of the more command because the pipe is usually implemented in the main memory of the operating system. The result of the command will display the output of ls -l one screen at a time but for a micro sec after which pipe will act like a container, which will take the output of ls -l and passes the result to more as input. Note: The more command will take the output of ls -l as input. Let us understand the concept of pipe command concept in more elaborate form with the help of the examples.ġ) Listing of all the files and directories and pass the input to the more command Some of the options are mentioned below :ġ) grep -I filename | sort: In this, the grep result will be fetched from the filename and will act as an input to the sort command, and the sort command will sort the data in default mode.Ģ) ls -l | ls File1: In this, the list of files will be listed, and the output of that will be transfer to the ls command to search the File1 from a bunch of files and directory.ģ) sort -r file.txt | grep -i “Country”: In this option sort command will take input from the file.txt and sort the data in reverse order and pass the output to the grep command, which will search the keyword “Country” from the data redirection. | commandNĪs the pipe is like a redirection operator, we can use it in different commands. The pipe command syntax is straightforward.Ĭommand1 | command2 | command3 |.