how-using-grep-egrep-command- find-single-multiple-words-pattern-linux-os

Using grep command to find single and multiple words pattern

Using grep command to find single and multiple words pattern

Using grep command to find single and multiple words pattern

Using the simple grep command, you can able to search for a single word.

but, how to search multiple words or parern of words using grep command on lunux Operating Systems.

For an example,  search words like error, warning, critical from a file
On our example, we are going to use the file /var/log/messages,

root@server [~]# grep 'warning\|error\|critical' /var/log/messages

If you want to match multiple text we need to add -w as option

root@server [~]# grep -w 'warning\|error\|critical' /var/log/messages

egrep is a command which we can use to skip the options

egrep command can be as below.

root@server [~]# egrep -w 'warning|error|critical' /var/log/messages

You can also use option -i and --color to see the grepped text colors.

root@server [~]# egrep -wi --color 'warning|error|critical' /var/log/messages

egrep
That’s is all on the grep and egrep command. This could help some one so we are writing this articles.
Encourage us by posting your comments.

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.