Receive all updates via Facebook. Just Click the Like Button Below

Pipes and Filters

Pipes and Filters are some of the important utilities in shell script.
Here we will learn the use of Pipes and Filters.

1

Pipes and Filters in Linux Shell Scripting

2

Pipes
A pipe is used to connect the output of one program or command to the input of another program or command without a temporary file. we use the symbol " | " for pipes.

Example:
Creating a new file " friends ".

 
cat > friends
abin
telson
rahul
manu
            

Press CTRL + D to save.

Now issue the following command:
sort < friends | tr "[a-z]" "[A-Z]" > FRIENDS
cat FRIENDS

Result:

 
ABIN
MANU
RAHUL
TELSON
            

The above command has sorted the file " friends " and using pipe the output was translated to upper-case letters and then redirected its output to the file " FRIENDS ".

Filters

A filter is a program that accepts input, transforms it or does something useful with it and outputs the transformed data. Some important filter commands are awk, tee, grep, sed, spell, and wc.

Example:

 
ls -l | grep -a "^d" | tee dir.lst | wc -l
            

what the above command does:
The ls command lists all the files and directories. The grep command takes only the directories. Using tee command, we write the result to the file " dir.list " and the wc -l prints the total number of lines in that file.

We have used 3 filters in the above example:
The grep, tee and wc.

3

Related posts:

Advertise here

picture picture

Follow us

picture

- Tech-Tutorials twitter.com/techcuriosity

Like us

About Techcuriosity

I am Telson, the webmaster of Techcuriosity.com and through this site, I share my knowledge and curiosities in the Tech World.


What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch

    techcuriosity@gmail.com
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture

    picture