Linux Command Line Tutorial For Beginners 37 - grep command

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to the next video on Linux command line to total beginners in this video we will learn how to use graph command in Linux graph sense for global regular expression print now graph graph command processes text line by line and print any line which matches our specified pattern so grab command can be used to search some kind of pattern or word or sentence in a text file or number of text file using this graph command and some options with graph c'mon so let's see how we can use grab command so first of all I need to have for example compile to use this crap command so I'm going to just change my directory to desktop first of all and then here I am going to create a file for example what I'm going to do is I'm going to use man and I'm going to use star and I'm going to dump the man page of star to a file for example I'm going to name it as file dot txt okay and then press ENTER it is going to create file you can see the file is created and when I'm going to open this file it's going to show the kind of man command output for the town right now I can use grab command on this file so I'm going to clear the terminal first of all and then let's open this file and let's see what we want the source for example for example I want to search for this word in this file called option right so I can use this command grab and then the pattern which I want to search for for example I want to search for options right so I will just write options here and then the name of the file in which I want to search my pattern in okay so grap and then the word I want to search and then the file name and then press ENTER and you can see it has searched the line which are containing the option key word right and when I open this file again we're going to show up so you can see this line is containing the option so this line has the spot name also so you can see this line is printed and then let's search here in the G edit editor also then you can see this line also contain 2 or option key word which is this line right and then we will go down you can see the options with the capital letter is not such because this crap command is case sensitive by default but we can use a flag called I to make it case insensitive and we are going to see in the next command but this will not be searched because the graph command is case sensitive right we will go little bit down and hopefully we see the next option line this is the next options line this is this one right so all the line containing option keyword is searched and printed right now I was talking about the case sensitive option right so to make the graph command to look for case insensitive word also so capital loss small the matter you can use eyes lab with it ok so if you use I flag then it's going to search for capital loss small letter words and when I print ENTER you can see it search for small letter options mine also and you can see it searches for the capital letter options keyboard also right now for example I want to print the line number in which this result is appearing so I want to print the first of all line number and then the result so I can use the option called the for example N and is for printing the line number right I can adjust remove this I which is for case in some particular right and when I print enter you can see on the line 9 I have this option then 17 and then 348 so I can prove this by just saying this so you can see this is line 9 you can see here line 9 column 29 right and then next is 17 here you can see line number right so join the collect result well now next is the flack we can use to for example we can use multiple you know keyword here also so it doesn't you know it's not necessary that this has to be a word it can be a sentence also right so for example I will do it once again and this time instead of option I will just see in the text what I want to search for example so I want to search for some options line okay not the keyword option but the sentence for example some option and instead of options I will just give this keyword called some option so come option and then click enter I just shows the line which contains this pattern which is some option so once again the line number is 17 as we know it search for this line only okay so this is also you can use you know graph command so you can also use graph command visit multiple file so let me clear the terminal and let me copy this file into different files so for example file two and then I'm going to create file three also for example and then file for also okay and then I want to search in these all four files something so let's search for this same option in different files so you can use the same command grab and - any for line number and then your pattern or sentence whatever you want to search and then the file name so it can be for file name and then while - for example and then file 3 if you want to certain file 3 and also file for if you want to search in file for and then press Enter and now you can see it giving the name of the file for and then the 9 number so file look dot txt contains just a pattern then file - dot txt contains this pattern on this line then file 3 contains this on this line and then file for also contains on this you know this pattern on this line right now this command you have to type all the file names right this can be made simpler with a wild-card so instead of writing this when you use s click it means all the files in this folder right so it means so v 1 v 2 v 3 and file for because these are the file which are there in the Desktop folder so this Astrix means that it's a wild card and it means that it's going to search for all the files and press Enter it's going to search or give the same result - you okay now sometimes you want to search for the line for example in the inverse manner so just search for the line which doesn't contain this pattern for example right so you can use a flag let me clear the terminal first of all and once again use a graph command and then whenever you use this V flag it means invert match which means that all the you know lines which doesn't contain this pattern is going to show these lines okay so it's the invert match okay and let me just you only one file for now file dot exe in then press enter it's showing all the line which doesn't contain this word which we are searching for let me also show the line number also so 10 I'm going to show the line number so it's only showing the line which doesn't contain the keyword which is some options right you can verify from here the terminal is not printing all the you know lines right but when you verify it it's not going to show you the line number 17 because this contains the term pattern which we are searching for okay so there are many are you know flags and options which you can use it graph command I just wanted to give you the introduction the gap crap command so go ahead and just use gap - H - that's right graph - H here and then press Enter it shows that to use help you need to use this command so not - H but graph - - help okay just use this - myself and then it's going to show you all the flag and options which you can use with the you know graph command so I hope you enjoyed this video please rate comment subscribe and bye for now
Info
Channel: ProgrammingKnowledge
Views: 65,270
Rating: 4.8350515 out of 5
Keywords: head command, tail command, whatis command, which command, kill command, top command, sudo command, mv command, linux tutorial, tutorial, linux, unix, bash, command line, guide, programming, Beginners, Introduction, basics, linux command line, Learn, examples, shortcuts, best practice, ls command, cd command in Linux, cd command, cat command, mkdir, rmdir, rmdir command, free command, ifconfig command, grep command
Id: _SxRZ4HMIBE
Channel Id: undefined
Length: 10min 50sec (650 seconds)
Published: Mon Jan 16 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.