In this lecture we will cover a group mighty tool.
Firstly let's open fire.
We have created in previous lecture and let's say that for some reason even the fine line of each contains
a word.
Second imagine did your file has more than ten thousand lines so searching manually would be horrible.
For that reason we can use grep.
So open terminal and write command and grep followed by a bottom.
You are searching if you specify a spartan and more rewards.
Don't forget to use double quotation marks and Dennis specify name of a file that the grep should look
for that but.
So in my case.
Article and icy output line which contains words second and similar to WC command grep is also often
used with cat command.
Using pipe.
Please don't be afraid that you don't understand by being now it will be colored lightly.
But basically what we are doing here is moving output of command.
In my case four lines from file called article and we are moving that output to grab command to process
it and search for a bottom.
In our case second in my article file there were only four lines.
So now I can work with something bigger.
For example passport file which contains all user's data for my computer and almost at the end
is mentioned user Richard.
Which is me.
So let's say that I want to display only this line from that file how to do that I can use God password
file by grep Richard and then I run it.
I see only desired output the same output I can get without by being using grep.
So grep Richard and specify the file in my case password file and the output is same as previously
do we have another option when using grep he we have.
So let's take a manual
and here is something which is also used very often and it is parameter old.
So let's find it here
barometer all brains only matched parts that means it doesn't brings a whole line where a button was
found but only the part which matched the pattern.
So let's state we can now close the manual and we can write grep
with parameter all
Richard because we are searching for pattern Richard and specify the file and now we see printed Richard
three times as it was found three times and other parameter which can be also used is parameter C or
count.
So let's search it.
Here it is.
It suppress normal output and brings a count of matching line
so if I tried I should get number one as only one line was found which contains name Ed
also what is good to mention is parameter V.
Parameter v selects non matching lines for the reason we can use it.
Let's see.
Create new file and call it config
open data file for editing.
And make their few lines starting with hash symbol
and then we can make one line which not start with hash.
And then two lines starting with hash again and again we can use some normal line without without the
hash at all.
And again two lines started to put hash and then we save it
we can now use get with parameter V
and I said but then we can use hash symbol and now back to a file in my case file config
and when we run it we see printed only two lines which has no hash inside which is good.
Imagine that you have 1000 commented lines and only two lines which are not commanded.
So for searching those two lines this parameter V is really good when checking the manual for grep command
we see button but button can be not only somewhat but also a regular expression.
So let's try with some regular expression.
So type of grep
followed by double square brackets and inside them call column digit Col on which is a regular expression
and represents all numbers.
So if in some line is no will get printed in line and if you see printed line with IP others which has
numbers.
Great.
Now let's edit our config file and add another line with some number
save that file
and then running grab command again we see now printed two lines.
Great maybe last thing to mention here is option how to print detailing or a leading context after or
before matching lines.
This option might not work on all grep versions but the vast majority should have it.
So we are a solution for context line control.
In the meanwhile
and here it is.
For example parameter a pretty specific number of lines of trailing context after matching lines.
Wow.
Parameter B brings bleeding context so let's use that and maybe the best instead of talking would be
to some.
Example.
So we can now print two lines which are after matching lines containing no
so for IP address it would be comment command.
And for number equals 5 would be only common because there is only only one line after it
so write and grab with parameter a
after that specified number of following line which would be included also in the output.
And we are searching for number in config file.
And what we see is exactly what I have told you.
We see IP address and following two lines and we see number is equal to 5 and following one line because
there is no other line in that file if we use parameter B we see printed two lines before matching lines.
That means before lines which contains number for IP address line which contain a number we see printed
two lines before and also for line number equals 5.
We see printed two lines before.
Good Please don't be afraid.
Did I didn't tell you anything about the regal expression.
Visual definitely covered lightly in much more detail.