- In this video, we will talk about cut
and sort, which are easy to use text manipulation utilities.
To start with, there is cut,
which you would use to filter out columns from text files.
If you want to use it the right way,
you do need to specify to the field the delimiter.
In cut, that is -d.
This -d is what you are going to use
to specify how cut can recognize fields,
and let's just have a look at two examples.
The first example is cut -f 3, etc, passwd,
then we have cut -d :-f 3, etc, passwd.
Let me show you.
So let's start with cut -f 3 on etc, passwd,
and what do we see?
Well, we don't see any fields at all.
It just prints the entire contents.
Why is that?
That is because it has no idea how to recognize a field,
and that is why we need to add the field's delimiter, - d :.
The colon is the field delimiter in this configuration file,
and if you specify -d :, then there we go.
We print the third field from etc, passwd.
Often used together with cut, there is sort.
Sort will sort the result of the cut command.
By default, it will do that in alphabetical order.
If you don't want it, you can use -n.
- n will sort in numeric order.
Let's just compare the behavior of these two commands.
First command is where we are using just sort.
Second command, where we are sorting -n.
So here, back to our previous command.
First, if you pipe through sorts, then what do we see?
Well, we see that this is how it is sorting.
So first, all the items that start with a one,
then all the items that start with a two.
That's probably not what you want,
and that is why you wanna do a numeric sort.
So sort -n is sorting in a numeric way.