WriteBash - This article will talk about sort command, how to use
sort command to sort pipeline data?
In the pipeline article, you already know the power when combining commands into a pipeline. It allows you to transfer data in/out between commands.
Sort command syntax
The sort command used in pipeline, so we have the following command syntax:
$ command-1 | ... | sort | ... | command-n
You can understand that the sort command receives input data from the command right in front of it. Then it sorts this data. And finally output that data to the screen or to another command in the pipeline.
Example using sort command to sort pipeline data
In essence, the pipeline is a way to filter data. And the sort command is like its name, it will sort the pipeline data into a sorted list.
Let’s take a look at the following example, we use the ls command to list all the files in the
/bin directory and
Recommended Reading: Overview of I/O redirection in Linux
The first is the result of the ls command without using
And when we use
You can see, this command has combined the output data from two folders on the screen into one and made it sort. Then export that unique data to the screen.
In addition, the sort command also has its options. The option that we use a lot is
-r, ie reverse sort.
$ command-1 | ... | sort -r | ... | command-n
You can type the command below to see all its options.
$ sort --help
This command is quite easy to use, its benefits in pipeline are huge. Jobs that require you to find a common denominator of data, then sorting data is essential.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.