Pipe, Grep and Sort Command
Pipe, Grep and Sort Command
Home
Testing
SAP
Web
Must Learn
Big Data
Live Project
AI
o
o
o
o
o
o
o
Pipe, Grep and Sort Command in
Linux/Unix with Examples
ByMary Brent
UpdatedOctober 29, 2022
Pipes help you mash-up two or more commands at the same time and run them consecutively.
You can use powerful commands which can perform complex tasks in a jiffy.
When you use ‘cat’ command to view a file which spans multiple pages, the prompt quickly
jumps to the last page of the file, and you do not see the content in the middle.
To avoid this, you can pipe the output of the ‘cat’ command to ‘less’ which will show you only
one scroll length of content at a time.
cat Filename | pg
or
You may manually skim the content yourself to trace the information. A better option is to use
the grep command. It will scan the document for the desired information and present the result in
a format you want.
Syntax:
grep search_string
Here, grep command has searched the file ‘sample’, for the string ‘Apple’ and ‘Eat’.
Let us try the first option ‘-i’ on the same file use above –
Using the ‘i’ option grep has filtered the string ‘a’ (case-insensitive) from the all the lines.
sort Filename
There are extensions to this command as well, and they are listed below.
Option Function
-r Reverses sorting
-n Sorts numerically
-f Case insensitive sorting
The example below shows reverse sorting of the contents in file ‘abc’.
What is a Filter?
Linux has a lot of filter commands like awk, grep, sed, spell, and wc. A filter takes input from
one command, does some processing, and gives output.
When you pipe two commands, the “filtered ” output of the first command is given to the next.
We want to highlight only the lines that do not contain the character ‘a’, but the result should be
in reverse order.
Summary:
Pipes ‘|’ send the output of one command as input of another command.
The Filter takes input from one command, does some processing, and gives output.
The grep command can be used to find strings and values in a text document
Piping through grep has to be one of the most common uses
‘sort’ command sorts out the content of a file alphabetically
less ,pg and more commands are used for dividing a long file into readable bits
Post navigation
Report a Bug
Prev
Next
Top Tutorials
About
About Us
Advertise with Us
Write For Us
Contact Us
Python
Testing
Hacking
Career Suggestion
SAP Career Suggestion Tool
Software Testing as a Career
Interesting
eBook
Blog
Quiz
SAP eBook
SAP
Java
SQL
Execute online
Execute Java Online
Execute Javascript
Execute HTML
Execute Python
Selenium
Build Website
VPNs