welcome to Section 103.7.
We're gonna look at regular expressions a little bit again.
We've already touched on some of these commands earlier, like said and grab.
But there's also some other options, such as E grap or Grab Dash E and F Grab, which is great dash F.
The group command gives us lots of
easy to use functions for
searching through files for different matching bits of text.
For instance, I can ignore the
the case of something I'm searching for. By using Dash I.
I can count the number of matches with Desi
Group. Dash V
tells me to match everything that, except for what I specified.
So that's kind of a neat thing. Its way to filter out matches.
Show me the non matching lines.
I could display line numbers
and get a little bit of more information about what I'm
trying t o find from a particular file.
So let's look at an example here
if I do a great dash I for the word error
and our log messages.
Actually, I got a copy of that locally here,
quite a few things show up
it's gonna get for this other file. All right,
now, how many lines actually had the word error in it?
What I could do
is count those.
So I'm gonna count and still ignore case. I know. I got 49 lines with the word error.
It's pretty handy to, uh, to see that. Now, How many lines would I have if I count those that do not contain the word error? Quite a few more. Right. So that shows me that
that's the rest of the file. Whatever doesn't match this particular
And I can also
display the line number where the matches occur.
I think you just need to do and bites out there ago. So there is my line numbers on the left side.
And that might be useful because maybe I want to know exactly where in the file these lines are located, because when the match happens, it just sends them to standard output without any regard for where they occurred within the file.
And this set example
shows Maybe I've got a word that I want to change. So I can say in this example,
capital user or lower case user replaced with user one
in a particular,
uh, text file.
It's another example of how we can use regular expressions.
You saw this table earlier with some of the regular expression details.
Zero or more matches, one or more matches,
digits, words beginning of the end of the line
and rangers of characters.
So if we look at some of these examples
I want to look for the word
ah, particular word, let's say on the word route
in a certain file,
I can use the carrot to match at the beginning of the line.
Now, if the route if if the If I ran this without matching at the beginning of the line,
I'm still gonna get a match. But it's gonna match in other places as well as you can see.
So it depends on what you're trying to accomplish.
If I try to search for roots at the end of the line,
I'm not gonna get anything because it probably
and should not exist in their file like password.
I could change this to bash,
now I can see that I'm matching the log in shell for a couple of my
users on this particular system
by being able Thio match at the end of line. I couldn't found those files are those lines in that file in other ways? But I'm on it.
More specifically say Look at the beginning and look at the end.
maybe I also want to
use egress, which is like Grab dashi, which says, Use regular expressions.
I'm gonna search at the beginning of the line
for character range. Let's say a through D. I want to find
all instances of
words at the beginning of the line that have this range of characters
we can see. I've got
a three D in these
beginning of the line items. So these air user accounts or log ins and around this system that start with those letters
and you get an idea for how powerful this these tools are.
Another great example. I can search for
digits that are certainly
so zero through nine,
and I'm going to use the currently braces to put a number in here,
and that should show me all digits that air four digits or greater
are all numbers rather than a four digits are greater.
I can do this with letters as well.
If I wanted to see all words that had
four letters in four consecutive letters together, I could do that.
So pretty, pretty interesting now, um,
grip, dash F or otherwise called F grab.
This allows me to
search for fixed characters.
So if I had a
a particular string I want to search for that might have
controlled characters embedded in it
I could search for It
helps if you spell it right.
Here we go. So there's
if there might be new line characters at the end of each of these. But I can search for that text anyway,
and I can even specify
if I had a file.
Sorry, I created a file
called Users Dot Taxed. It just has a couple of user names in it
so I can
do a grip dash looking for literal characters,
and I could use something like an input file.
And now it takes
these these values in the file, including whatever new characters are new line characters, maybe their character turned characters
and still allows me to do the search within the target file.
So these kinds of commands are a little bit tricky to get used to, but with a little practice you can get more familiar with how to
do the basics of regular expression matching beginning and end of line and things that are in the middle of the line.
And if you're looking for through error logs and things of that, nature is really helpful techniques to have.
So that gets us to the end of the regular expression section. Next will look at V I
So you, then thank you.