Hello, everyone, and welcome again to our newer lesson said Command said command is a substitute command
which replaces or substitute a text with another text or manipulate your file.
It is a very, very powerful command.
So what are the few things that said command does?
It replaces a string in a file with another string.
So a string is a word, a sentence, text message or any kind of text message inside of your file and
that you want to replace it finds and deletes a line.
So if a line has A, B, C, and you want to get rid of that line in that text file, well, you could
go in and use the set command and delete that line that contains ABC.
Now, wait a second, Emran.
Hey, why can I do the same thing when I go to V.I. and find the line and delete it?
Yes, you could definitely do that.
But what if you have a file that has, let's say, a million lines and in those million lines you probably
have at least a thousand lines that has ABC.
Now, are you going to go into the file and delete or replace that string one by one?
You think that is efficient?
Not at all.
So that's why I said command is so powerful that allows us to manipulate the text inside a file.
Another example that we learn is how to remove empty lines from our file if they are more than one empty
line.
How can you get rid of it?
Yes, of course.
Going back to the same thing that you could go into the VI and and remove it.
But again, this is not productive.
Remove the first line or number of lines in a file to replace tabs with spaces.
These are the few very few examples of set commands that I'm going to go over and substitute within
via ed.
So if you are already in V.I. and you want to replace a text X, Y, Z or text or anything with another
text or another word, you could also do by going straight into the V.I..
But again, am I negating my statement what I said before?
No, because when you are going to the VI and you you when you look for one word and then you replace
it again, it's a manual process.
But there is another way in VI that you could just find that text one time and it replaces it everywhere
in one shot.
And there is so much more and more that is that said commands has to offer.
So I'm going to log in to my Linux machine.
I'm going to log in as a PUDI client, and I will show you a few examples of how set command works.
I'm logged in as myself.
I am in my home directory.
I have a file in my home directory.
That is called this stimulus mysel to your dad is called Seinfeld characters, so if you do cadd on
Seinfeld characters.
You will see all these characters of Seinfeld again, it's just a list of all the characters that played
in Seinfeld, if you do not have that file or if you did not create that file previously, then go ahead
and you could just pause it right here and create that file with all those names that I have.
Or if you want to use a different file, a different name, that's fine.
It's just the example that I'm going to be using to explain how set command works.
So I already have this file.
Now, the first thing I wanted to do, let's say, what if I wanted to replace one of the word with
a different word?
Let's say I wanted to replace Kenny.
There's a character named Kenny Banyo.
How about if I wanted to replace his name from Kenny to Lenny?
You would use the command said.
Single code is for substitute.
Kenny.
Wedd.
Lenny, to slash Lenny and slash again, and if you if there are more than one Kennie, then you could
type G because this G is stands for Global.
It will replace the entire file wherever you have the word kennie.
So by default, I always use G.
You should also get into the habit of G if you want to replace it every way.
So you hit, you close the single quote and then you type the name of the file where you are trying
to replace the word Kenny hit enter and now you will see at the bottom it is replaced with Lenny.
Now, another thing I do want to mention that this is going to display the change only on the screen.
It is not actually going to make a change in the file.
So if you get out the file, you will see.
The name Kenny still there, but didn't we just replace it with Leny?
Yes, we did, but it did not make the change inside the file.
It only makes the change to the screen.
And if you want to have that output to another file, you could do that.
And that change will be reflected in the newer file.
But if you want to make a change to the existing file, then what do you have to do is.
You come back to the same command by heading up key and you type minus I, that is to insert the changes
into the file, the same command and you hit enter.
Now, when you Dukat, Seinfeld characters, you'll see the name has changed to Lenny permanently.
So this is how you replace Caneva Lenny and save the file.
Now let's see what if you want to replace the word Castanza.
So it works the same way, so you do said.
Substitute Castanza.
And this time, you just don't want to replace anything, you just want to remove that word, so you
just put Castanza and don't put anything in there.
Gee, and the name of the file.
Characters, you see any anyone who had the last name Constanza, that is gone.
See right here, Frank Costanza is gone.
Stelle is gone.
Another Castanza I have.
The bottom is gone.
George Costanza is gone.
But again, this is gone only on the screen.
And if you want to make a changes to the file, you have to use the minus eye option.
I don't want to use the minus high option at this time because I wanted to show you how the set works.
So this way the world won't change.
So just let's just confirm our file has all the correct names that I want to have them in it.
So it does have it.
Next one I wanted to show you is how to find a string of line and remove it.
If you see, this is the second one in our slide, find and delete.
So what if I wanted to delete every line that has the word Seinfeld to for the command to do that is
said.
Seidenfeld.
And this time, Type D.
D is to delete any character or any word that comes up that matches Seinfeld, that line will be deleted.
So I am not using minus option because it will actually make the changes to my file and save it.
I just want to show you.
So I just I'll just run it and you will see all the lines that had the Seinfeld.
Argon, see, none of this has the word Seinfeld in it, so that's how you replace or delete a line
that matches a key word or a word, the next thing I wanted to show you is how you could remove empty
lines from a file.
So if I have empty line, let's make the empty line.
I'll go into Seinfeld characters.
And I'm going to make empty lines.
So I have four empty lines, right, I'll just make one empty line right here as well.
Five empty lines.
Now, I'm going to save that file.
Kat Zionsville.
Characters.
And you will see right here I have.
Five empty lines.
I wanted to get rid of these five empty lines, the command to do that said.
Stasch.
Cap caps shows that anything that starts, which is right above number six and anything that ends with.
Dollar, meaning nothing, then just delete that.
So sorry, I signed Phil characters, so anything that is starting or anything that is ending has nothing
in the middle, which is the empty file, of course.
Right.
So whatever that finds, please go ahead and delete it.
So hit enter and you'll see everything is gone.
But now if you do sign for the character again, you'll see you'll still have the line.
Why?
Because we did not specify the minus option.
And I want you to go ahead and specify minus I option do assign those characters and you'll see all
the empty lines are gone.
Now, what if I wanted to remove the first line in a file?
I just wanted to remove Jerry Seinfeld, which is the first line of the file.
So I will do said Code one D code.
Close the name of the file and you'll see the first line will surge.
Jerry Seinfeld.
That is gone now, of course.
Again, I'm keep saying it is not going to affect our file because we did not use mine.
So I option.
Now, what if you want to remove the first two lines?
Well, hit up our key and just type one, comma two and it will delete the first two lines.
That's how you delete two, three or four or more lines.
Now what if you have tabs in your.
In your file, and you wanted to remove those tabs with spaces, so if I do V.I. on Seinfeld characters
and instead of spaces, I'll just put Tab's tabs and tabs.
Save the file, you could do Seinfeld character and you see three lines Hattab, I wanted to remove
all the tabs inside the pile with space.
So the command to do that is said substitute slash.
We have to use backslash and t that tells the operating system or the shell that this is a tab.
Anywhere you find tab, please remove it with space and apply it globally.
Seinfeld characters you see.
OK, they don't like something.
One second.
Oh.
My mistake I used.
Backslash you have to use for slashes here because.
This slash right here and this slash right here in the middle right here is the strength that we are
trying to replace.
We are trying to replace that string with what would seem like sonar that should work.
And there it is.
It did work, but it is, again, not going to impact our file.
I'm going to use that command with minus I option so it will make the change to my file and bring it
back to its original content.
OK, so now that's how you actually replace tabs with spaces if you want to do the same thing or play
spaces with tabs, you could do the same thing.
But just switch up backslash T with with the second space holder.
So you move this thing to here so it will remove everywhere.
So let's say you if you want to try it.
T.
And so any spaces that it's in there, please replace it with TAB.
And I have to put.
This year.
OK, so I believe.
So both characters and there you have all the tabs in there, I did not want to make the changes, that's
why I when I was checking it, it was not coming up anyway.
I wanted to bring it back to bring it back around earlier command, which is this place to have its
bases and hit enter and now do Seinfeld characters.
And you'll see my format is back the way I want.
OK, now what if I wanted to show only lines from 12 to 18 from a while, so I just wanted to view it
12 to 18.
So one, two, three, four, five, six, seven, eight, nine, 10, 11, 12.
So I wanted to see all the lines, starting with J.
Peterman all the way to the end, which is the 18th line.
I don't want it to view any of these lines.
So for that, we'll use the command set again with mines and option 12 from 12 to 18.
P is.
The option that you have to pick and you hit enter and you will see right here, it's giving me from
line 12 to 18.
Now, what if you wanted to view the opposite way, meaning you wanted to view everything except line
eight, 12 to 18, then you will run the command said now don't use minus and use 12 18.
D this time and Seinfeld characters, and you'll see you have all the results from the top except starting
line 12 to 18 now.
What if you wanted to put a put a space in your in your file like every name, there should be a space,
there should be a IMT line after each character.
So you'll do said just gee Seinfeld characters.
And you see every line has a space empty line then the name empty line, then the name.
This is how you added.
But of course it's now going to impact our file.
You could you could have that changes by putting in my A.I. option.
OK, now what if you wanted to replace like let's say if I have signed filled character and I wanted
to replace Seinfeld with S or any other name, but I do not want to replace no line eight.
So one, two, three, four, five, six, seven, eight.
I wanted to replace Seinfeld with S except the eighth Seinfeld.
So you said.
Single quote, Do not do aid and substitute.
Seinfeld with s do it.
Globally.
Seinfeld characters.
OK, see it?
Did it change?
Oh, once again, we see.
No.
Let's see.
So if I just type A just a subdued type of an S., so it is still not doing good, am I doing something
wrong?
Yes, I am doing something wrong.
See, sometimes just a tiny bit of a mistake makes a huge difference.
If you notice there is no such word.
Assign fled.
I put sign fled.
All right.
It's a good exercise.
You hit enter.
You see every Seinfeld text or word has been changed with S.
But now let's go back to our original question.
I don't want to replace number eight.
Fixed my spelling enter and you will see all of them have changed to except line number eight.
Now, the last one I talked about substitute while you are in B.I, Ed, so go ahead and type by the
name of the file.
And now you are NBA editor.
Now, what if you wanted to replace every single character while you are in the eye, so you will do
Callon?
Percent sign says, for substitute slash.
Sign Felde.
To.
Peter.
Right.
You want to replace every one of them?
And slash, hit, enter, and you'll see every sign furled has been replaced with the word Peter.
That's how you make the change while you are in the ED.
Now, I want you to go ahead and try it out.
I have also an article mentioned here in this lesson that you could view that article and try all the
different commands.
Again, said, command is very powerful if you really know inside out.
So I would encourage you to try many different ways.
Go ahead and do do your Google, go online and search for anything that you wanted to do with said.
And I promise you, every time you type something, make sure you type like how to replace a string
in said command, make sure you put in set command.
And I'm telling you, you're going to find tons of articles out of the people.
Again, have done amazing job who have helped people.
And you could look at their article and see how things are done.
You can learn on that.
All right.
If you have any question about set command, you could just simply send me an email or message me.
All right.
Good luck.