Hello and welcome to the lecture of OK, this is one of the commands for text processing commands,
ORCH is a very powerful command and we are going to try a few commands that also has to offer.
So what exactly is an arc alkies as utility or language designed for data extraction?
And most of the time it is used to extract fields from a file or from an input.
So let's try a few commands of our OK.
And I have my Linux machine open right here on the side.
I am logged in as myself.
I logged in as Pudi, I logged in through the Pudi, OK and a hostname, which is a server name on my
machine is my first Linux VM and I am in my home directory.
Perfect.
Now go ahead and clear the screen by typing.
Clear.
Now let's go back to the slide and in the slide we'll go over the first command and the first command
is to check the version of OK so OK, space dash dash version will give you the version of the of the
OK utility when it was written and who wrote it and SPU description of the OK, go ahead and clear the
screen and try the next command.
The next command will actually list the first column from a file.
So let's go to our Seinfeld directory, which is in our home directory.
In that directory we have a file called Seinfeld Characters and this is the file we will use for this
lecture.
So when you do Cat Seinfeld characters, you're going to see the list of all the characters or the contents
inside this file.
And this file has two columns, as you can see, by the first name and the last name.
What if you want to get only the first name, which is the first column of this file, then you will
run the command.
OK, single coat, curly braces, print $ one, curly braces close, single chord close.
And the name of the file in our case is for Seinfeld characters, and you're going to see it only giving
us the first column of this file.
If you if I wanted to get the last name, which is the second column or second field of this file,
then I'll do print dollars to you.
Could just simply by the way, you could just simply hit up Arrow Key and come back using the left our
key and change the value.
So in this case, I'm going to change it from one to two and leave everything as is and do the right
arrow key to go all the way to the end and hit enter and you will see it as giving me the second column,
which is the last name of all the characters inside the Seinfeld characters fault.
Then we have the next command.
As what if you want to list the column of an output.
So not just the actual the contents of a file, but actually the output of of of a command.
So if I do this myself in my directory, which is home, I have those Seinfeld, you see, I have these
columns, which is a permission and links the user group size month, date time and the file name.
All these different columns are actually fields.
If I wanted to print the first field, which is the permission field and the third field, which is
the user ownership field, then I could simply do this minus L Orckit.
Single code, calibrated, printed, dollar one, comma, dollar three, culebras escrows, single code
close and you will see you only going to get the first and that their column.
See how powerful alkies moving on.
What if you wanted to get the last column of an output?
Now if you do A minus L tr and what if you wanted to get this last column, you could count it by saying
one, two, three, four, five, six, seven, eight, nine, that it is a last column.
So you hit up Arrow Key and and you just put in a dollar nine and it will give you the last column.
But there is an easier way instead of you for counting every column, you could just type an F that
will automatically gives you the last column of the output so they don't go.
So it's a print dollar.
Nine is the same as print dollar and F, which gives you the last column.
Then what if you wanted to search for a specific word from a file using all command?
OK, so I can also do the search for you.
So let's say if I have a file cat title characters and in that file we have all these characters.
What if I only want to search the line that has the word Jerry I could use?
OK, single code slash Jerry, make sure you specify the exact as uppercase G, slash curly braces,
print what it found and quote close and the file name, which is Seinfeld.
And it is giving us the Jerry Seinfeld, which is the first line from our file.
As you can see, there is no other line in my content that has Jerry in it.
What if I wanted to do the same thing, but instead I wanted to do Seinfeld, so I'll do s e I and field
that.
And now you'll see there are two Seinfeld in there, Jerry Seinfeld and Maury Seinfeld.
So it matched the exact keyword that we are trying to search for.
Next commander will try is what if you wanted to get the list or the feels that is separated by a delimiter?
In this case, we will use that C password again, as similar to as what we use in the cut command.
So if you do cat atse password and you see every field in this file is separated by colon, so you could
also use a command here instead of cut command to get the fields.
So if you wanted to get the first feel, which tells you the username, only then you could use Orch
Dash minus F.
The limiter and in this case, the delimiter is Callon, and then single code curly braces, $ one,
curly braces closing the cold closed and etsi password.
And you'll see you got all of the user names from that file, same thing, what if you wanted to get
the home directory?
So Home Detective know that it is actually the 6th field.
So you type six and you'll get all the home directory.
So cut and all in this regard works similarly.
Next one will learn is what if you wanted to replace a column that matches a certain key word.
So let's say if you do echo Hello Tom.
And in this case, the dollar too is Tom.
So it will replace Dollar with Adam and I'll print it.
So let's try it.
So when you do it, go.
Let's say hello, Tom, and you hit enter, it will echo it out and it will echo back to you, right.
So when if you run this command again by heading up Arrow Key and you do OK.
Single coat, curly braces, dollar two, and in this case, dollar two, we all know is Tom and I want
to replace Tom, let's say, with Adam and we type Adam here.
Clothes, and then we do.
Colon, not a semicolon, sorry, and then print dollars zero, print dollars zero dollars zero, meaning
whatever it font, it finds it now.
So we will do curly braces, clothes and court clothes, single court clothes and hit enter.
And you will see now instead of doing Hello Tom, it is doing Hello Adam, because we replace the second
column with Adam, just like that we could use we could also use our Seinfeld characters.
So let's do Cadd on Seinfeld characters file right now.
What if I wanted to replace every last name with my name?
So my name is Emran, right, as you all know.
So I want my name to be as a last name for every second column.
So in this case, I will do is Cat Seinfeld and I will do OK.
Same thing.
Dollar two, which is the second column equal.
Double coat Emraan, double cold clothes, semicolon, print dollars, zero curly braces, clothes,
single cold clothes hit enter and you will see now every last name is my name.
That's how you could change.
That's how this command becomes so powerful to make changes to your file.
Moving on.
What if you wanted to to replace the second.
Oh I already did that.
Perfect.
So I'm one step ahead.
This is something that I just showed you.
Then next one is OK.
What if you wanted to get the lines that have more than 15 bite size?
OK, so if you do catch Seidenfeld, you probably noticed there are some names that are smaller and
there are some names that are bigger like this, George Steinbrenner and Estelle Castanza.
So these are the bigger names and it has a bigger bites.
So what if I only wanted to get the names of those lines or the lines that has those names that has
more than 15 bytes or lente 15 characters.
So I will do first of all, I look at Seinfeld and then I'll do OK.
Or I would I could do instead of carrying it, I'll just start with OK and I'll put the filename at
the end then.
Single single Lent.
Parentheses dollars zero parentheses closed greater than 15 single code clothes, and the name of the
file in this case sign character and you will see it is giving me that those two lines that A has to
size the length that is more than 15.
If you do 14, it will find a few more.
It also found this time it also found George Costanza.
So that's how you could use this all comen in terms of the length then a moving on, get the feel to
matching Seinfeld and.
Slash home slash high of Zolt.
So when I do and I go to my home directory, just type it and you see you are in your home directory
in my home directly.
And I do a list minus L.
I have all these files and directories.
Now, what if I wanted to get the list that only matches Seinfeld?
I'll do this myself.
OK.
Single quirkily basis if.
Parentheses dollar nine, and we all know a dollar nine is the last column you could do.
Dollar nine or you could do an F..
Equal, equal.
Double coat.
Seidenfeld.
If it matches Seinfeld, then you have to print it so print dollars zero semicolon and then you have
to close it with curly braces and then a single coat and hit enter and you will see, oops, I got some
error message.
Let's see where else minus L OK if the all or nine equals Seinfeld.
Oh I didn't put the parentheses right here so I had a Parakey.
I have to put the parentheses to close.
My argument, and now I hit enter and it will give me only the file or a directory that matched the
last field or the ninth field as equal to Seinfeld.
Then the last one, I'll give you an example of the command is what if you want to find the total numbers
of fields in a file or in an output?
So let's say if you run plus minus L here and you count it to find out which column that you wanted
to get.
Right.
So let's say if you looking for the last column and you wanted to know how many columns is this output
has, you could count one, two, three, four, five, six, seven, eight, nine.
Or you could just simply run a command that's minus L and Orckit print it and F no no dollar and F just
NF curly braces close and single could close had and it will tell you it has nine fields.
The top one that you see two is actually when you do X minus L you're going to see right here on top
is this total 280.
So you could just ignore that.
It's basically giving you the two fields and the rest.
Every line has nine fields.
So this is all about OK, there is there are there's so much that you could do with all command at that.
Probably I don't have time to cover, but you could go ahead and try to do always man on.
OK, to find out what are the other options that you have.
There are also GAAP or PG, aka d.g, OK, and there's different ones that you could use and there are
different options that you could use.
Try every one of them if you have time to, so you have a better grip on the command, OK.