Now you can search all of them together with grep using the “-R” command. To make things easy for you, you create a new folder containing symbolic links to all the various log files that are of interest to you. After all, many packages have their own locations for log files. Let’s say for example, that you have a bunch of log files scattered all around the system. However, we can also use it to search an entire directory of files at the same time. We normally think of grep searching either a file or a specific output from another command. Searching an Entire Directory for a Match and Showing the File Name If you want to remove the “words” requirement and instead just want a straight up string match, then you can drop the “w” parameter. We can match as many words as we need to that way. So the above command becomes: egrep -w 'sparrow|dogs' animal-count To make it even easier, we can just replace “grep -E” with “egrep”. -w means that we only want to match whole words.-E means that we’re using extended regular expressions.We can use the following grep expression: grep -Ew 'sparrow|dogs' animal-count Let’s say we want to search this file for these two phrases: To start with, we have a file called “animal-count” with the following contents: However, we can use regular expressions easily with the “-E” parameter. Normally, you’d have to use a separate grep expression for each of these phrases. You want to check the log files for the existence of some keywords that span a variety of sources. However, let’s say you have an error log file and are performing routine maintenance. Where ‘pattern’ is any given pattern or regular expression to match. Normally, the usage for grep goes something like this: grep 'pattern' filename Searching for Multiple Words at the Same Time Searching an Entire Directory for a Match and Showing the File Name.Searching for Multiple Words at the Same Time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |