Learn Grep with 15 Amazing Examples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi friends I welcome you to yet another series of a very important Commander levels and today we are going to learn correct amount right so grab is a very powerful form on life find right but it is generally used more for text searching and manipulation we will learn the entire command using 15 amazing example okay so what is grab grab stands for global such a regular expression and print so grapple is a command-line utility for searching plaintext data and set up on a set of lines matching a regular expression so how it works you just type drab and then you have the string in the inverted comma and the file name and when you enter the button it will just search it out the entire file for that particular string so Graham was initially developed by Ken Thompson for unique operating system but now reality that it is present in almost all the versions of unix-like operating system okay so let's learn a very this example of it so how do I do a simple web search so I will I'd wrap suppose if I want to search this string I will put it will be inverted comma and then ever mentioned we move of the file okay so if I want to see this by example family side program I will save this okay I will say I want to show just a string then I will say ABC dot txt okay so you see our graph has searched this particular string in the in this entire file okay so let's go back to our tutorial now we we have such a basic string but suppose if I want to search it into more I'm in different file format so I can have your text file I can have a CSV file the same name for how would I go about it so I will use wildcard star to have more than one format of the file or I will use the star for searching everything instead of the file ok whatever we can also do case-insensitive search it's very simple and easy you just need to mention - in front of it and so and it will do it for you similarly you can use regular expression and search anything you want okay so let's see a small demo message so if I want to do grab - Tyson program then I said this string which I am looking for and then I do suppose if I want to look into multiple file you see it has searched this particular string in CSV file in the text file ok so similarly if I want to search the same thing but in case insensitive fashion and how would I do it I will say - I and you see when I use - I I have this in caps and this is a small cap from it so if you want to use case in subtle insensitive search you have to go - I okay so let's go back to the tutorial now what if I want to do a regular expression search I want to find a line but I'm not sure of the word in it so I can use regular expression so what would I write I would say from ramp okay sorry time is G see I said crap and then I will this vaguely write the word that I remember so I would say something something and then I will say empty and I will say the file lame okay so you see I didn't remember the complete line but using the regular expression I can use it this is how you use regular expressions which clear to use all its power right okay so let's go back to the tutorial and see and move forward okay so next is full word search suppose if I want to find exactly the word is then I have to use hyphen W right I will make it case insensitive right similarly I mean most of the time when we are debugging our force or we are doing some textual writing right so we we don't actually want to see that particular word in the file we also want to see some lines above it some signs around it sometimes below it how would I do it so that is very simple using using - a caps - a and you mentioned numbers of lines that you want to see after the match and the string after after the data string matches and the file name so what will it do it will print three lines after the example string matches in a in this file and a - I for take case insensitive search similarly if you wants n line before it you use - B if you winds want n line up around it so you say - see okay so we'll just see the practical version of it first we'll clear B okay so so this clearly thing and then this one okay so I say program I - I W and I will search is in ABC not star you see I have all the lines that have is in the complete fashion okay similarly I mean if you want to see the difference I can show you okay okay so let's move to the N lines after the maps so I will say a I suppose if I want two lines after a word fall amazing so after this word appears I went to line up for it you see it matches here and then it returns to line absolutely okay similarly if I want two lines before it I will say P and you say the mode matches here and it spins to line before it okay similarly if I want two lines around it how would I do it I will say cap C and it will the word matches here and it gives me two lines above it and two lines below it so it's of great importance I tell you I mean we use a lot while debugging our foods and playing with it okay okay so how you know grep generally looks for the match in the current directory only by the point right so if I want to search recursively in all the subfolders how would I do it I have to use - R along okay similarly if I want to invert my searching right I have to use - V and most of the time you may not require the exact matches you may just require the number of key matches they use - see okay so let's go and let's test it back clear out and save some problem with my keyboard also so I'd say percussive searching web - our and suppose if I want to find one cotton mean in all the files since it will clutter ice cream so I just want to see the counterfeit using WC - L and we have just hit enter and we are waiting for the result that it will give right so now what Graham is doing with rap is looking for this word in all the files and folders right all the files and folders in the current direction right and after that alpha it will pass pass it on to this utility called word count what it does it will count all the up commands of this mean string right and it will list the home so it is 28,000 25 times this whatever ok this it has searched all the directories I mean you will recursively similarly if I want to in word researching what would I do so it will set only the current directory and it has say there's 15 files it does not have this word ok so similarly if I want to see recursively write that how many how many strings we have which does not have a current of this it is this much right so you understand what I'm trying to say similarly if I just wanted to count the pattern why so I just want to count right I don't want to use this WC - are using crap I can do it all alone so what it does it goes into each folder and file and it will mention the number of occurrence of the match you see you see so it in these folders it have occurred for 0 time but in this folder you see it occur in this many times so it has not occurred sorry because we have inverted researcher so if we want to see how many times it have occurred then we will have to hit like this ok okay similarly if I want to recursively see how many files does not have made in the entire direction so it will gasps give all the files along with the count okay after they finally give the house okay so now let's move back to our tutorial okay so we have already seen I mean the counting thing right after that I think this okay suppose if I want to display only the files which matches the given pattern so we want to see only the file that matches the given pattern for this I have to use capital I okay similarly if I want to show the position of the matching in line and then I just want to show the position where the board has exactly matched then I need to move behind - V right and if I want to use the exact word match then I have to move oh okay so here you can see how to grab - oh and - be pattern okay similarly if you just want the line number of it you say - L okay will clarify are all the things in our okay practical sessions so I would say grab - are I sorry I and I am looking for a word called teacher okay and let's see how the how it does okay so it it matches exact word teacher recursively and it has found all this up so for exact match you have to do step okay similarly if I I want who I want to see the exact this word match okay I will say W right so if it just bring out the exact word that will happen it will not search for me anything where you have a word like this right so here it was matching this word and it had some other things also but it still it just did but when we did - W it means it sure that it actually message matches with each other okay so now if I want to see the position right what would I say I would say e and it shows the position at which this particular word has occurred so if I want to find different very sick okay and similarly you can put o for the exact language okay so it makes it short that you are actually matching this okay and if I want to see the line number also what would i do i will say high end and show me the line number this is the line this is the place that that particular word has occurred right this is how the graph does I mean it's exceptional come on and it's very helpful for analysing editing mainly debugging social that I use it for and it's wonderful I use it with fine then it is amazing it so this is how we close our today's session hope you enjoyed please subscribe and like the tutorial and encourage us to add more informative tutorial okay we are signing off bye
Info
Channel: Linux Tutorial
Views: 194,296
Rating: 4.5038166 out of 5
Keywords: +grep, +grep command, +grep in linux, +grep unix, +learn grep, +grep examples, +grep with examples, +grep with 15 amazing examples, +learn grep with 15 amazing examples, +linux, +unix, +best tutorial for grep command, +best grep, +greap command made easy, +search strings in linux/unix, +regular expresssion, +learn grep in 10 minutes
Id: o1C2Fqjrqgs
Channel Id: undefined
Length: 14min 50sec (890 seconds)
Published: Sun Jun 01 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.