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.
Pipes and Filters in Linux Shell Scripting
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.
Related posts:
- Shell Scripting Introduction
- Shell Syntax
- Shell - Strings
- Shell - Variables
- Shell - User Intraction
- First Shell Script
- Shell - Arithmetics
- Shell - Case Statement
- Shell - Command Line Arguments
- Shell - For Loop
- Shell - While Loops
- Shell - IF Statements
- Shell - Input Output Redirections
- Shell - Pipes and Filters
- Shell - Process Management
Your IP address1 is: 172.18.0.2
Tutorials
Latest Updates
Follow us
- Tech-Tutorials twitter.com/techcuriosity