1
00:00:01,280 --> 00:00:05,210
In this lecture we will cover a group mighty tool.

2
00:00:05,830 --> 00:00:07,110
Firstly let's open fire.

3
00:00:07,110 --> 00:00:14,710
We have created in previous lecture and let's say that for some reason even the fine line of each contains

4
00:00:14,710 --> 00:00:15,280
a word.

5
00:00:15,280 --> 00:00:22,860
Second imagine did your file has more than ten thousand lines so searching manually would be horrible.

6
00:00:22,970 --> 00:00:25,560
For that reason we can use grep.

7
00:00:25,730 --> 00:00:32,820
So open terminal and write command and grep followed by a bottom.

8
00:00:32,840 --> 00:00:36,500
You are searching if you specify a spartan and more rewards.

9
00:00:36,500 --> 00:00:44,810
Don't forget to use double quotation marks and Dennis specify name of a file that the grep should look

10
00:00:44,810 --> 00:00:45,960
for that but.

11
00:00:46,250 --> 00:00:47,750
So in my case.

12
00:00:47,750 --> 00:00:59,320
Article and icy output line which contains words second and similar to WC command grep is also often

13
00:00:59,440 --> 00:01:01,010
used with cat command.

14
00:01:01,030 --> 00:01:02,600
Using pipe.

15
00:01:03,040 --> 00:01:08,130
Please don't be afraid that you don't understand by being now it will be colored lightly.

16
00:01:08,170 --> 00:01:13,480
But basically what we are doing here is moving output of command.

17
00:01:13,540 --> 00:01:20,620
In my case four lines from file called article and we are moving that output to grab command to process

18
00:01:20,620 --> 00:01:22,940
it and search for a bottom.

19
00:01:22,960 --> 00:01:28,810
In our case second in my article file there were only four lines.

20
00:01:28,810 --> 00:01:32,250
So now I can work with something bigger.

21
00:01:32,320 --> 00:01:43,130
For example passport file which contains all user's data for my computer and almost at the end

22
00:01:49,270 --> 00:01:51,300
is mentioned user Richard.

23
00:01:51,400 --> 00:01:52,680
Which is me.

24
00:01:52,750 --> 00:02:06,810
So let's say that I want to display only this line from that file how to do that I can use God password

25
00:02:06,810 --> 00:02:13,960
file by grep Richard and then I run it.

26
00:02:14,010 --> 00:02:22,770
I see only desired output the same output I can get without by being using grep.

27
00:02:23,580 --> 00:02:32,610
So grep Richard and specify the file in my case password file and the output is same as previously

28
00:02:36,020 --> 00:02:40,400
do we have another option when using grep he we have.

29
00:02:40,400 --> 00:02:41,410
So let's take a manual

30
00:02:46,020 --> 00:02:54,860
and here is something which is also used very often and it is parameter old.

31
00:02:55,780 --> 00:02:56,770
So let's find it here

32
00:03:01,110 --> 00:03:08,430
barometer all brains only matched parts that means it doesn't brings a whole line where a button was

33
00:03:08,430 --> 00:03:12,060
found but only the part which matched the pattern.

34
00:03:13,230 --> 00:03:21,650
So let's state we can now close the manual and we can write grep

35
00:03:24,680 --> 00:03:26,250
with parameter all

36
00:03:28,890 --> 00:03:38,320
Richard because we are searching for pattern Richard and specify the file and now we see printed Richard

37
00:03:38,410 --> 00:03:50,660
three times as it was found three times and other parameter which can be also used is parameter C or

38
00:03:50,660 --> 00:03:51,090
count.

39
00:03:51,350 --> 00:03:58,280
So let's search it.

40
00:03:58,540 --> 00:03:59,450
Here it is.

41
00:03:59,560 --> 00:04:04,960
It suppress normal output and brings a count of matching line

42
00:04:09,250 --> 00:04:17,270
so if I tried I should get number one as only one line was found which contains name Ed

43
00:04:22,140 --> 00:04:25,500
also what is good to mention is parameter V.

44
00:04:29,540 --> 00:04:35,650
Parameter v selects non matching lines for the reason we can use it.

45
00:04:35,810 --> 00:04:37,550
Let's see.

46
00:04:37,550 --> 00:04:42,840
Create new file and call it config

47
00:04:51,490 --> 00:04:53,890
open data file for editing.

48
00:04:55,770 --> 00:05:00,380
And make their few lines starting with hash symbol

49
00:05:14,990 --> 00:05:18,820
and then we can make one line which not start with hash.

50
00:05:25,220 --> 00:05:32,780
And then two lines starting with hash again and again we can use some normal line without without the

51
00:05:32,780 --> 00:05:34,790
hash at all.

52
00:05:34,790 --> 00:05:38,210
And again two lines started to put hash and then we save it

53
00:05:41,620 --> 00:05:45,330
we can now use get with parameter V

54
00:05:48,320 --> 00:05:58,030
and I said but then we can use hash symbol and now back to a file in my case file config

55
00:06:02,880 --> 00:06:09,710
and when we run it we see printed only two lines which has no hash inside which is good.

56
00:06:10,110 --> 00:06:17,150
Imagine that you have 1000 commented lines and only two lines which are not commanded.

57
00:06:17,220 --> 00:06:24,750
So for searching those two lines this parameter V is really good when checking the manual for grep command

58
00:06:24,810 --> 00:06:29,780
we see button but button can be not only somewhat but also a regular expression.

59
00:06:30,210 --> 00:06:32,980
So let's try with some regular expression.

60
00:06:33,120 --> 00:06:34,410
So type of grep

61
00:06:37,650 --> 00:06:48,240
followed by double square brackets and inside them call column digit Col on which is a regular expression

62
00:06:48,300 --> 00:06:50,580
and represents all numbers.

63
00:06:50,580 --> 00:06:58,050
So if in some line is no will get printed in line and if you see printed line with IP others which has

64
00:06:58,050 --> 00:06:58,710
numbers.

65
00:06:58,730 --> 00:06:59,510
Great.

66
00:06:59,580 --> 00:07:05,370
Now let's edit our config file and add another line with some number

67
00:07:09,290 --> 00:07:10,400
save that file

68
00:07:15,930 --> 00:07:22,210
and then running grab command again we see now printed two lines.

69
00:07:22,590 --> 00:07:30,750
Great maybe last thing to mention here is option how to print detailing or a leading context after or

70
00:07:30,750 --> 00:07:33,280
before matching lines.

71
00:07:33,330 --> 00:07:40,050
This option might not work on all grep versions but the vast majority should have it.

72
00:07:40,050 --> 00:07:43,710
So we are a solution for context line control.

73
00:07:43,740 --> 00:07:44,730
In the meanwhile

74
00:07:48,870 --> 00:07:50,550
and here it is.

75
00:07:50,730 --> 00:07:56,940
For example parameter a pretty specific number of lines of trailing context after matching lines.

76
00:07:57,240 --> 00:07:57,730
Wow.

77
00:07:57,750 --> 00:08:07,000
Parameter B brings bleeding context so let's use that and maybe the best instead of talking would be

78
00:08:07,000 --> 00:08:07,420
to some.

79
00:08:07,420 --> 00:08:08,520
Example.

80
00:08:08,710 --> 00:08:14,710
So we can now print two lines which are after matching lines containing no

81
00:08:18,080 --> 00:08:20,480
so for IP address it would be comment command.

82
00:08:21,440 --> 00:08:28,640
And for number equals 5 would be only common because there is only only one line after it

83
00:08:31,500 --> 00:08:36,540
so write and grab with parameter a

84
00:08:39,370 --> 00:08:48,540
after that specified number of following line which would be included also in the output.

85
00:08:49,190 --> 00:08:52,010
And we are searching for number in config file.

86
00:08:54,560 --> 00:08:59,780
And what we see is exactly what I have told you.

87
00:08:59,940 --> 00:09:07,380
We see IP address and following two lines and we see number is equal to 5 and following one line because

88
00:09:07,380 --> 00:09:19,950
there is no other line in that file if we use parameter B we see printed two lines before matching lines.

89
00:09:20,010 --> 00:09:28,320
That means before lines which contains number for IP address line which contain a number we see printed

90
00:09:28,410 --> 00:09:33,660
two lines before and also for line number equals 5.

91
00:09:33,690 --> 00:09:36,270
We see printed two lines before.

92
00:09:36,270 --> 00:09:41,490
Good Please don't be afraid.

93
00:09:41,490 --> 00:09:44,900
Did I didn't tell you anything about the regal expression.

94
00:09:44,990 --> 00:09:48,300
Visual definitely covered lightly in much more detail.
