We have given the pattern list in the file pattern.txt and then ran grep command against it with ‘-f’ flag. ![]() Try the below patterns and see what you get Same as previous example and this time it returns the line which contains the character ‘h’ Learn t hings step by step at Devopsideas It returns empty since there is no word that contains the character ‘z’. The above command checks for the presence of the character ‘z’ in the file. Next we can see some example that deals with character reference The same command with the additional flag -i (insensitive) resulting in the count to be 2. This will not be counted since we did not pass the case insensitive flag ‘-i’ as a result of which we get the count as 1 You can notice one of the line ends as Devopsideas. Hence we get the count as twoĪbove command will list the lines that end with devopsideas. In our example, 2 lines start with the word devopsideas. ![]() The same command with -c flag will give the count. ‘^’ is used to indicate “starts with” in regex The above command will display the lines that start with the word devopsideas. ![]() If possible, copy it in a notepad so that it’ll be easy for you to refer instead of scrolling up every time when we discuss about different examples. We’ll be using this content all through our example. Grep is majorly used in parsing files / standard input by matching the given pattern and displaying the matching lines.Ĭonsider the file file.txt contains the below content. Grep is one of the most commonly used command in conjunction with piping for anyone who works with Linux based systems. Lets quickly breeze through their usage with some basic examples. This will be a nugget on usage of grep, egrep and fgrep.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |