|
To use the grep command to search for multiple strings or words, how do we do? For example, I want to find / path / to / file file word1, word2, word3 and other words, how do I look like grep command these words are there?
grep command supports regular expression pattern matching. To use multi-word search, please use the following syntax:
grep 'word1 \ | word2 \ | word3 ' / path / to / file
Under the example, to find a name in / var / log / messages log file in a text warning, error and critical these few words, enter:
$ Grep 'warning \ | error \ | critical ' / var / log / messages
Just to match the word (that is, both sides of the word is a word delimiter, separated by spaces for the West in terms of language), you can add -w option parameter:
$ Grep -w 'warning \ | error \ | critical ' / var / log / messages
egrep command can skip the above syntax, the use of syntax is as follows:
$ Egrep -w 'warning | error | critical ' / var / log / messages
I built the righteous of you add -i (ignore case) and --color option parameters, as shown here:
$ Egrep -wi --color 'warning | error | critical' / var / log / messages
Fig.01: Linux / Unix egrep Command Search Multiple Words Demo Output |
|
|
|