grep command in Unix

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome to tech skill YouTube channel if you are new to my youtube channel please subscribe and hit the bell icon to get notification of new video let's begin today's lesson today we are going to discuss about grave common so grave is a filter command in UNIX and it is used to search a particular pattern in a file and it will print in the prompt so that pattern is refer as a regular expression and grave stands for stands for globally sorts for regular expression and printout so let's see practically to see it practically I have created some sample file let me show you cat so as you can see this is one sample file I have created let me increase the font here so this is one sample file same way I have created one more sample file this is another sample file so I have created three sample file and the content is same in each file so let's see it practically so let me clear the screen to clear the screen ctrl + L now this is my file now let's say you want to search UNIX so graph and you give the pattern which you want to search so here I want to search UNIX in which file this is my file and so you can see we got UNIX so we are every UNIX is present the whole line will be printed here okay so you can see here so UNIX is presenting four lines only the UNIX word you might be asking there are some lines which contents UNIX which starts with capital letters it is not printed because we are searching only this one same way if you want to find x Kelly and give the file name our file is you can see so this is how you will use grep to search a pattern in a given file now if I want to search the same pattern in each file in multiple file so how I will do this one say if I want to search eunuchs so in multiple files sample dot txt so you can see so it is telling that in this file so we have two lines are there these are the two lines which is present in this the name of the file is engrave on Rosco sample dot txt so it will display the file name along with that line which contains that pattern that we are searching so same thing here also here also same thing so you got how to search in multiple files okay let me clear the screen now I want to search the same word let's say I want to search in grave skill and I want to search in the complete directory so in directory I may have ten five or hundred files so it will search in all the files and it will display wherever it is present sorts in all directory so we have to give star so you can see its present in this three files is present in this STD file dot txt so it's present here in and it is present in unique file underscore two unique file so if you have not watched a CD command and unique command so see my previous video so this is how you search in a particular file or in a particular directory whichever pattern you want so now we will see some other options available in Grif see we are writing grave eunuchs and give the file name so you can see here so this is eunuchs is present in four lines but there are some other lines like if I'll go there are some other lines which also contend eunuchs were like this one this line you can see this line also and you can see this line also so these lines are not printed here because we have written eunuchs and it is considering only this particular one that means it is guest sensitive so how you will make it as a case insensitive so we have one option that is a grave type and I and give the word which you want to search or the pattern and give the file length that is great sample dot txt and you can see here all those seven lines are printed here which contain the word eunuchs so here it is guests insensitive so we have to use now son - I okay so next we will see in how many lines the word is present count of lines so for this we have to use grave - see and eunuchs can give the file lamp you can see the eunuchs is present in four lines and we have sorts here and it here also it is for line but you know the eunuchs water is present in seven lines as you can see in the this command so here we can mind these two option that is grave I can see and you can give ie so you can see here so now it is showing in seven lines let me clear the screen now I want to see the line number also if hyphens in which line number that pattern is present so grave - M and I want to see UNIX grave and give the file name our file is grave underscore sample dot txt you can see it is present in line number 3 5 8 and 10 so if you want to make it is case insensitive give type - I also now you can see it is present in all the line number it is displaying wherever the word UNIX is present as we have one more of some - V and we are searching UNIX graph sample dot txt so what it also it is the reverse of what we are searching means we are searching this pattern so it will tell wherever that pattern is not present displayed at all you can see now so wherever that UNIX is not present it is displayed in this line index is not present indexed in this line also it is not present in this line it is present but it is case sensitive so if you want to make it in a case insensitive so you can use pipe - eye of Sun you can see so it displayed all those lines we are the UNIX pattern is not present okay so let me clear the screen so now we have one more of some Gryff - L so I want to sort this water so my requirement is to know this pattern is presenting which file I don't know the file so I want to see in which file it is present so if I give you can see it is showing the star means source in the current directory so it is telling me in these files the pattern textile is present now you can go and you can get from those files next we have grave - whoa and I want to search UNIX in grave sample dot txt so it will give only the UNIX but it will not give complete line you can see if you want in which line it is present so you can combine with - n so line number three five eight and ten it is present and you can use all those options together also now I want to sort this one let's say I want to highlight UNIX I want to highlight with some color now take this plain okay so you can use this - - color option to highlight the pattern which we are searching so it will highlight you can combine this with - I also so you can say so this is all about the sun's available engrave command so here we learn how to use the grip command and the options so friends hope you have enjoyed this video so if you liked this video please share and subscribe with your friends thanks for watching stay tuned for such interesting video
Info
Channel: Tec-skill
Views: 2,508
Rating: undefined out of 5
Keywords: grep, grep command, grep in linux, grep in unix, grep with example, grep example, unix tutorial, linux tutorial, regular expression, best grep tutorial, linux for beginner, unix for beginner, unix grep example, linux grep example, learn grep in unix, learn grep in linux
Id: 5PoMMVYywhE
Channel Id: undefined
Length: 12min 57sec (777 seconds)
Published: Tue Mar 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.