


The following command will print the same output: $ grep -R -include=*.

The first part of the command looks for the word Walden in any. You’d use this command: grep Walden grep Pond. Test/log/app_20200301.log:DATETIME - SQLException has OccurredĪs we can see, the file test/app/readme.md appears in the output as well.Īlternatively, we can also use one single –include option and let the GLOB expression contain multiple extensions. Say you want to find files containing both Walden and Pond on the same line. Test/log/app_20200401.log:DATETIME - ClassCastException has Occurred Test/log/app.log:DATETIME - NullPointerException has Occurred Test/app/change_log.log:Fix the NullPointerException Problem when calling external APIs Test/app/readme.md: - Exceptions are well handled To Find Whole Words Only Grep allows you to find and print the results for whole words only. In this example, we use nix as a search criterion: grep nix The output shows the name of the file with nix and returns the entire line. Now, let’s search for the word “Exception” on *.log and *.md files: $ grep -R -include=*.log -include=*.md 'Exception' test To search all files in the current directory, use an asterisk instead of a filename at the end of a grep command. –include=*.log is an example of the –include=GLOB option, which tells grep to only search files whose basename matches the given GLOB expressionĪlso, we can use multiple –include=GLOB options to ask the grep command to search on files that match multiple extensions.That is, it’s going to search the given pattern in files in any subdirectory under test
