[Autogenerated] Now, of course,
whilst knowing the very basics of re app and
regular expressions is really useful.
And the foundation of our knowledge, we want to push this a little bit further.
We've already seen that we can use RE app minus C to count the number of
lines and to even count the total of number of lines.
In this case, the services file,
the services file is used to map port numbers through to the service.
They represent, they also sit on top of transport protocols, maybe UDP or TCP.
So if you want to look for lines that contain either UDP or TCP,
we can group them together using parentheses.
But to implement the group,
we need to specify this as an enhanced regular expression.
So we're using the option minus E,
if we want to see everything other than UDP or TCP,
we can go through and specify to irreverse or invert our expression.
So we're seeing then all lines that don't contain UDP or TCP
where it's preceded by a forward slash,
we could then go through and look at the other transport protocols that are
available S C T P and D D P and then just print those lines.
So we've been able to dig a little bit deeper and
understand more about our services file by understanding a
few little options inside of re app.
But we can also use that inversion to remove comments and empty lines.
So we can count the number of lines in our SSH fi.
This is available on all of our systems and is
usually available to standard users.
If we want to remove many of those lines,
as many will be commented or empty,
we can use re minus V E as we saw before to invert and use the regular
expression engine lines beginning with a comment or the end of line marker
comment is just the hash symbol as I'm sure you'll know.
But now we're able to see the effective settings and really useful.
Remember we're not editing the file so the comments are still in the file.
But when we're looking at the configuration,
we can see what is set rather than trying to
understand that from all of the comments.
Now, really to get into this,
we need to go out and practice and it's like anything practice,
practice, practice is going to make you the master that you want to be.
So I really do encourage you to join me at the command line where we
run through some of these examples that we've seen.
And yes,
we're diving out of that command line when we're going to
move on from our basic regular expressions.
B R E and take a look at our enhanced regular expressions, the er E engine.
So we're going to be using groups with our parentheses and we can then
go through and use our enhanced regular expression.
We can use the option minus V to invert our regular expression.
And these basic skills are going to allow us to have much more control of
filtering the entries that we want to be able to see.
Come on, let's go through and take a look at it.
Now, the first thing is to count those lines that we have in our services file.
So we can go through and use word co if we want.
But we can also just use repo this to res minus C and let's go through and
count from forward slash E T C forward slash services.
This services file is got 578 lines and it is representing then the common
port numbers that we use and the service that it represents.
If we want to go through and start then looking,
we can dig a little bit deeper with grip.
And if we use our enhanced regular expression,
we can then go through and specify that we're looking for a forward slash.
That's not a meta character.
That's just literally the string forward slash.
But we want to then look for UDP or TCP services.
So this is where we can use our enhanced regular expression,
our parentheses,
creating a group and inside of that group we can or so we can say TCP or UDP,
we can close off our parentheses.
That's what we're looking for.
So we can close off our string, our regular expression,
an escape and dot To bring up our services file.
So we should be seeing both TCP and UDP services here.
Now again, we can go through and count these up if we want,
so we can specify the option minus C to count.
So we've got 518 obviously,
that's slightly less than we saw before with some kind of 570 some odd.
If we want to then go through a, an,
an understand the differences if we reverse our expression.
So I'm changing the option minus C for count to be minus
V to invert our regular expression.
We're now not going to see those lines that contain UDP or TCP.
So we can start seeing.
Well, again, there are some commented lines here.
Of course, there are some empty lines,
but we can also start seeing there's some different protocols,
their D D P, their data gram uh protocol,
an S C T P.
Well, if we want to just list these, let's clear our screen and then go back,
maybe not count them.
Maybe we'll just go through and print them,
but we can then go through and take a look at the D D P and S C T P
doesn't matter the order that we search for them.
But we're looking then for these two strings coming directly after the
forward slash and we can see then the results coming back.
So it gives us a great idea to be able to investigate a file
and see some things that are perhaps less common than we
would normally be able to see.
Now, there is one really good example for you,
but let's follow it with another really useful example.
Very often when we as administrators are working with configuration files,
we have a lot of really useful comments.
Those comments can explain what configuration settings do,
but also they sometimes hide the configuration from us.
Let's go through and take a look at a file that we're all
going to have and have access to as a standard user.
And that's our SSH underscore config file.
It's going to be heavily commented and we can see this by going
through taking a look at forward slash E T C and the subdirectory
SSH and the SSH underscore config file.
Now the comments can be really useful,
but here its just show me some of the default settings so
those settings that we don't need to make.
So it's not too bad, but we can see that everything is just about on one page.
But what if we only want to see the effective settings?
Well,
this is where we can go through and use the same
tools that we saw before with re app.
So re app minus V E.
So invert our enhanced regular expression.
And let's look for lines beginning with either the
end of line marker or the comment.
So we can group those two characters together and then go
through and look at the SSH config file.
And rather than having our whole page of information,
look, we only actually have four lines that are actually configured.
Now, we haven't deleted any of the comments, the comments are still there.
However, when we're looking at what actually is configured,
this can be really,
really useful allowing us to see the information that we need really quickly.
And this is why I'm a big fan of regular expression and a big
fan of tools such as RE app and sd an org that we're going to
be taking a look at as well, but we're not quite finished with grip yet.
In our next demonstration,
we're going to be taking a look at how we can go through and search
multiple files for a configuration if we're not certain which file
actually holds the configuration we want.