[Autogenerated] Hello and a really big and warm welcome to this plurals site
presentation where we take a look at the stream editor.
My name is andrew Mallet and I'm going to be your instructor helping
guide you through looking at sd or our stream editor.
The stream editor can be used to select lines by either
the line number or a regular expression.
We're also going to be able to insert app end or delete
lines as well as replacing text by learning.
Said, one of our real important tools from our command line,
you're going to learn that you can programmatically edit files,
even those on remote systems.
So come on,
we really need to get into learning said and seeing
how we can harness its powers.
So as we start looking at sd,
we're going to begin by selecting lines by their line number and
that's going to be easy if we know the line number.
So for example, we know the first line of a file is going to be line number one.
So yes, of course,
we can print line number 11 and P to print sd would normally print anyway.
So we can choose minus N.
So we only select those that match the pattern.
The problem we're going to have though,
if I want to print the last line without counting up all of the lines,
we're certainly not going load the line number,
but we have a special character that we can use there.
The dollar.
Now, this is different to the dollar, which we use in a regular expression.
That would be the end of the line.
But the last line in a file is known as dollar.
So this can be really useful.
So if I just want to print the last line of a file, we can use dollar P.
Now, as well as being able to print the line number,
we can always work with a range of lines,
whether we want to print those lines or even edit those lines.
But for the moment, we're just getting used to the print command instead.
So if I want to print lines one through to three, we can use one comma three.
If I want to print from line 20 through to the last line of the file,
then it's 20 comma dollar,
remember dollar representing the last line of our file.
Now, of course,
the very best way to learn is by getting some hands on experience.
And I really do encourage you to join me at the command line
so that we can all practice this together.
We want to become used to using ed and selecting lines by their number.
So we're going to start learning the very power and essence of
said our stream editor and we're going to begin by taking a
look at selecting the line number,
a range of numbers and that mythical last line,
come on, let's find that command line.
And here we are just about to get used to using sd, our stream editor.
So I can go through and use sd.
We can go through and put our regular expression so I can just have
this as single quotes and we can go through and look at E T C slash
pass W D and we can see from that, that it prints the contents anyway,
if I then use the print command.
So let's go through app P in here.
We're going to duplicate all of the lines.
So we're actually printing each line now twice to avoid this,
we can use the option minus N.
So we suppress the standard output and then only match
lines that our pattern has selected.
And of course, we haven't really selected every anything at the moment.
So that then comes back to printing everything.
But this then becomes a great way of actually showing those lines that we meet.
If I clear the screen and then start making some use of this if I go through
and put in our line number one and just print that one line,
those lines that meet our pattern.
So of course, we're just getting the one line coming back if we want to print,
let's say lines 1325, we can use comma 51 through to five.
So this thing becomes really useful if we want to be able
to select lines by the line number.
But of course, very often we want to be selecting the last line.
And without counting all of the lines,
we don't know what line number that's going to be.
So thankfully sd has thought of this and we can use then the dollar character.
So we can then go through and using this as a number,
we can use dollar P and now we're printing the very last line.
And of course, I can still use this within a range.
You know, if I go through and say print from line 25 through to the last line,
then we're looking exactly at that from line 25 through to the last line,
we can see then it's printing from underscore R PC.
If we wanted to check that, let's clear our screen.
So control and L our arrow key and let's try printing line 25.
So 25 P and we can see then line 25 actually is then our underscore R PC.
So if we're always a little bit doubtful of it,
well, don't worry, run a test to prove that it is actually working,
but we can start seeing how powerful this can be even when
we're just looking at selecting lines.
But there's a lot more that we can do and line numbers and
printing are just one side of things.
Remember, this is our stream editor.
But the moment we want to get used to selecting lines and we're
looking at selecting lines here by the line number,
have a go yourself play around with different line numbers and then start
seeing that you can really control the values being returned.