[Autogenerated] And yes, look at this,
the lovely blue indicating that we are really going to start our learning.
We're going to be taking a look at the re app command and the
start of our journey with regular expressions.
We're going to begin with some easy to understand examples.
We've seen some of them that we'll be running through within the slides.
But it's your practice that really becomes important in your understanding.
So we can become used to grip.
And more importantly,
some of the regular expressions that are going to be really
important with working with our text files.
We can begin by searching our E T C pass W D file which we all have.
And it gives us then an idea of how we can use some of
our meta characters within our search.
But as we've seen,
we can move into other standard files such as our services file.
Come on.
Why don't you join me now?
And yes, for most of our demonstrations,
we'll be working just on my raspberry pie.
When I look at the host name C T L command,
we're going to be able to see the operating system that we're running and we can
see that we're using Sian and that Buster is the code name.
Now, this is a Debian based system so very similar to Debian itself or to Ubuntu.
But it shouldn't really matter the operating system that
we're using so long as it's error, recent Linux distribution.
Now,
the first thing is we're going to go through and take a
look at searching for information.
So if I go through and clear my screen,
if I just go through and say Grip and we'll look just for an empty string,
I can use double quotes or single quotes.
It's not going to make any difference really with an empty string.
But when we look at that for our E T C slash pass W D,
we haven't said what to look for.
So because we haven't shown a regular expression,
we're able to then print absolutely everything that we've got.
And we've seen that we can implement then account if
we don't want to show the lines,
we just want to count the number of lines we could use minus C.
So we're counting the number of lines.
Now, of course,
we have got specific programs that will do this such as the cat command to list
everything and our word count to count the number of lines.
But its just showing you, we can do this all with repo.
Well,
we look for a specific user if I go through and run
Grip and look for the root account.
Now, I don't have to put quotes around it.
The idea of putting quotes is to protect any meta characters that
we're using and we're not using any meta characters.
So it doesn't really matter.
But it's always a good idea to think of quoting your regular
expressions so that the characters that we use are not
going to be expanded by the shell.
But don't forget if you want to pass variables through,
then we're going to be using double quotes and we can go
through and look at our password file, remember,
escape and dot is a great way,
a shortcut to be able to bring up your last argument.
So here we've been able to isolate just to the root account.
Now,
we're looking for the string route and we can see that
we match it on the user name route.
It's also in the comment field and it's also the users home directory.
So we're getting three matches if we add in a meta character.
And if we use the carrot, the hat symbol,
some people call it but its upper case six on a US keyboard.
We're saying the line begins with root.
So you can see now with the color coding that we get with re app,
we are only matching on the first line.
We're still looking for a string route.
If we had a user account, let's say called root ball,
we're still going to match on root ball,
but there's nothing stopping me putting an extra character afterwards.
We know at the end of the user account name, we are going to get a colon.
So we can see now where we go root colon,
we're matching on the route and the column.
So this is our full user name.
Now, when we run this on a Debian based system such as Rasp we're using here,
we only get the one line coming back.
Anyway, if you are using Fedora or a red hat based system here,
we're using Alma Linux nine.
But if I go through an grip for root in my E T C pass
W D file here as we look at it,
we get both the root account and the operator account.
The operator account is set to use the root users home directory.
So we get two matches.
So we can kind of see why we're going to have to be careful about our searches.
If it's important, the lines that we're getting back,
obviously going back now to change this.
So that the line begins with root is going to ensure that we're
only getting the one account coming back per say,
we can drill down to become more accurate to put the
colon after the t of the root account.
So we're looking for the root user and only the root user,
we're just showing the differences on other operating systems.
So you can understand the differences yourself if you're not using
the same operating system as I'm demonstrating.
So this gives you an idea of some of the things that we can use.
But as well as the beginning of the line, we can look for the end of the line.
The beginning of the line we've already said is our carrot or hat symbol.
The end of the line is a dollar.
So both of these symbols,
the hat or Carrot and the dollar are going to be useful.
If we look at using the end of line,
we can go through and look for bash being at the end of
our lines in the E T C password file.
So this is then showing us those users have the default shell of bin bash.
If we wanted to count those, then of course,
we can just go through a minus C how many users
have bash as their default shell?
Well, it's two now, obviously here,
it's really easy for me to count up because there's not a lot of
difficulty in counting two lines even I can count two lines.
But why don't we go through and just take a look at our services
file if I go through and just look at word count minus L forward
slash E T C forward slash services.
This lists my protocols and ports that are used to access
those protocols and we've got 578 lines.
So a little bit more.
But if I want to look at, let's say just the TCP lines,
I can go through and say grip and let's look for forward
slash TCP inside of my E T C services.
So we can see how the services file is laid out.
But of course,
we've got many protocols that work on top of the TCP transport protocol.
So if I clear this, if I just want to count those lines,
we can go through and use grip minus C, so we can count those lines.
If we want to go through and say count our UDP services,
we can then go through and change it through to UDP as the transport protocol.
So this gives us an idea of some of the basic usage
of grip and regular expressions.
We've looked at just strings,
but we've also used the meta characters for the beginning
of the line and the end of the line and looking at ways
that we can implement them.