How can I read a file and display only the relevant lines using grep?


This question already has an answer here:


You can use

grep -v "xinetd\|nrpe"

Sure, you can use first_pattern|second_pattern together with the -E option of grep:

tail -n 2000 /var/log/messages | grep -Ev "xinetd|nrpe"

From man grep:

-E, --extended-regexp

Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.)

$ cat a
hello this is me
bye this is me
and that's all

$ grep -Ev "hello|bye" a
and that's all

grep -v "xinetd\|nrpe"

is correct and sufficient. Options like -E or egrep are not necessary.

More variaties:

grep -v "^xinetd\|nrpe"   # exclude lines starting with xinetd, and any nrpe"
grep -v "xinetd$\|nrpe"   # exclude lines ending with xinetd, and any nrpe"

Need Your Help

How to customize variable "next" in Django login form?

django django-forms

In Django login, we see a variable called "next" to redirect to the next page after login. How to control this variable?

How to design and implement a simple WCF service relay?

web-services wcf authentication routing

We are in the process of designing a simple service-oriented architecture using WCF as the implementation framework. There are a handful of services that a few applications use. These services are ...