All right, let's move into sought and unique comments again, they are still part of the text processing
commands, so let's see what exactly are sought and unique commands sought command source in alphabetical
order.
And as the words is a self-description of itself as its source down the file, the content of the file
or the output in alphabetical order from A to Z, whereas unique command filters out the repeated or
duplicate lines.
So if you have a file that has two similar words and two different lines, it will eliminate one of
those lines to show only one.
So it will remove duplicates.
All right, let's try a few of our commands in our Linux machine and the first commands as all of us
to check the version and check the help.
So I am logged into my machine as myself.
My host name is my my first Linux machine and I am logged into my home directory.
Perfect.
Cleared the screen and tried, according to the version getting the short version.
Here's the version.
Let's try to help command and you'll get all the help with all the different options that is available
to you and always tell you do man on sword to get more information about sort of UNIKOM it.
All right.
Next command is short file.
So let's go into our Seinfeld directory and we have a file, their side of characters, cat, the Seinfeld
characters.
And this is the content of the Seinfeld characters, of course, all the characters, pretty much all
the characters with the Seinfeld show.
Now, if I wanted to sort this, as you could see right now, it is not sorted because Jerry is J and
C is for Cosmo is should be up before Jerry.
So if I wanted to sort all of this, the entire list by the by the in alphabetical order, then I would
simply have to do is support Seinfeld characters or the file name hit Enter and you will see now it's
sorting by the alphabetical order Elton Benice, Beeb's, Cosmo, David Elain and all the way down is
Uncle Leo, because Uncle Leo is starting as you by the way, Uncle Spelling is not correct.
That's fine.
It's just a matter of explaining how short works anyway.
That's you sort out a file.
Next one is if you wanted to sort in reverse order.
So if you do support Seinfeld, it'll give you a line that starts with a or the first alphabetically
in the first line.
If you want to reverse it, you do sort minus R and of course the name of the file and it will give
you Uncle your the top alten bonus at the bottom if you wanted to short by that field number.
So let's say by default when you just type short by default, it actually starts sorting from the first
letter or the first column.
What if you want to short by the second column or the second field, then you specify that field by
typing Sorg minus cave and number two, meaning we wanted to be y just short by this second field.
And then the name of the file now is sorting by the second field, Kenny Bania and Isleton.
Now Altan should be up, but since we are doing with the second column, you'll see Banyo is the one
that comes in the first as going through the alphabetical order.
If you had if you had three columns or three fields or four fields, then you could always pick that
field and put it in here and change it with that order.
Anyway, we don't have that.
That's why by default is picking the first one.
Moving on a unique command.
Let's find the unique come out.
Of course, it removes the duplicates.
So if you type just simply unique.
By the way, before I go to Unique, we worked on the catting the file, but how about we do ls minus
l let me go to my home directory and this is my home directory.
Now if I typed ls minus l you going to see the list of all the contents.
Sorry, all the files and directories in my home directory.
Now if I wanted to see them in the alphabetical order I will just do this myself, type it to sort and
it will sort in alphabetical order.
C it will go always go.
Start with the first letter and first letter says I have d a deal.
This comes first and why.
But while going through the D then I'll go to the second column.
I have all the way down to the name of this second to all of it and column.
What if I wanted to sort by the last column and we know and we do ls minus L the last column is this
one which is No.
Nine, so if I do a short hit up arrow key, go to the command that we run and just type minus nine.
Of course you have to do this myself first.
Now do A minus L type short K minus nine.
Now you're telling it to shorted by the last column or the ninth column in this case is this column.
So as you know D there's no way if there was a it would have been on the top.
So that's how you do on the output of a command as well.
Now let's go to Unique that I want to clear the screen and go to Seinfeld directory I have assigned
by the characters file.
And if I do unique on it and do Seinfeld characters, I'll still get the same list.
Why?
Because I do not have any repeated
lines in my in my Seinfeld characters file.
So in order for four to to show you how this unique works, I am going to add a line to this file that
is a duplicate line.
So I'll do ATCO and I'll put Jerry Seinfeld one more time.
Into so double coat to append it to the file and then the file name signed by the characters hit Enter
and now do on Seinfeld characters, you're going to see there is one Jerry here and there is one Jerry
Seinfeld here.
Perfect.
Now, if you do this sort and Seinfeld, the characters, you're going to see Jerry Seinfeld right here
coming up.
And right after another perfect, that's what the sword does now, if you just try to do unique on Seinfeld,
you're going to notice that Seinfeld, Jerry Seinfeld is the top right here and Jerry Seinfeld bottom
here.
It still did not remove the duplicates.
Why?
Because here's a rule of thumb, guys.
Every time you need to run as unique on any of the output or content of a file, always run short.
So that's why I have it here sort of file and then unique all the sort first before using unique their
line numbers and the line numbers, of course.
So if I do sort you Seinfeld hit enter now it has arranged it for me.
You see it has arranged the Jerry Seinfeld, Jerry Seinfeld right next to each other.
Now if I hit up key and pipe it to unique, now you will see that duplicate will be gone.
Hit, enter.
You see, there's only one Jerry Seinfeld left, that is why very important that you do sort of first
on any file or output before you run unique.
Next one is sort file and unique.
See meaning sort first and unique and list the count.
So hit up Parakey and just type C will give you that.
All of them have one one one one one one one except Jerry Seinfeld, which has to.
That's what I wanted to know.
That's why I ran this comen meaning give me that unique removed it duplicates.
But I still wanted to know how many times that duplicate showed up and is saying that duplicate showed
up twice.
Beautiful.
OK, the next one is short, unique minus show only repeated lines.
Meaning I only wanted to see the one that are repeated.
So I will do unique minus D and hit enter and now it is only showing me the line that has been repeated
or that is a duplicate line.
All right.
Now since we did the sorting on the fire, let's do on the output meaning you run any comment I am picking
ls minus Elter so don't get stuck stuck on a minus lta.
You could pick any command that you like, even if you do that's a P WD and you could do unique on a
short and or anything you like.
But anyway and you do it will always gives you one line.
That was a bad example anyway.
So I'll go into Eliz minus L and add it is in my Seinfeld directory.
I will get out one step back and now I'll do a less minus L because they'll give you give me a lot of
directories involved.
So I would like to play with this one.
So if I do X minus L and then I'll do a short and then I'll lose unique, it's still not going to give
me anything because every line here is unique.
That's why it did not give me.
So the point is you could use sort and unique on files as well as the output of any comen.