Before moving further into this concept, I would like to tell those enthusiasts who wants to make their future or create something in Big Data/Data Analysis then you must definitely know this core concept of Piping.
You must also have bit more knowledge about the input/output redirection.Here, we just have to work on two things:- 1. Output giving commands in Linux. for eg:- date command, cal command, rpm command etc. 2. Input giving commands in Linux. for eg:-tr command, cat command, grep command, wc command etc.
In Piping, we attach both output giving command and input giving command by sending this output giving command as a input because he needs it.By this way, it creates a pipeline between these 2 commands.In Linux O.S, if we have to send i/o of these commands then we have a symbol ‘|’ named pipe symbol.
We’ll try to understand this concept with an example- we will send output of cal command to tr command by using piping.
In Linux,cal command is a calender which displays us the current month and year. This command always sends output data.
cal December 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 //output//
tr command is used to convert lower case letters to upper case letters.This command always input data.
tr ‘a-z’ ‘A-Z’ qw teryu gdhfj QW TERYU GDHFJ Bnm yutr BNM YUTR //output//
#Now, we will use piping concept here,which will convert those lower case letters from output of cal command into the upper case letters.
Here,date command will send the output to the tr command,whatever input tr command gets from date command he will use ‘|’ pipe symbol to further convert it.
cal | tr ‘a-z’ ‘A-Z’ DECEMBER 2018 SU MO TU WE TH FR SA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 //output//
Here,you can see all the lower case letters are converted into upper case letters. We can combine more than two commands using piping concept.This is a very simple concept,easy to use and create.We can perform as many manipulations using Piping concept in Linux O.S.
You may use ‘tee’ command if you have to send your output to multiple location.
for eg:- date | tee f1.txt //f1.txt is a location//