For eg
I would like search for "ModLoad" in my rsyslog.conf file
So when attempted without any switch or argument with grep
# grep ModLoad /etc/rsyslog.conf
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
$ModLoad imklog # reads kernel messages (the same are read from journald)
$ModLoad immark # provides --MARK-- message capability
$ModLoad imudp
$ModLoad imtcp
So I get a whole bunch of stuff there but what if I would like to grep only the text "ModLoad" and nothing else
# egrep -o ModLoad /etc/rsyslog.conf
ModLoad
ModLoad
ModLoad
ModLoad
ModLoad
ModLoad
Here I have switched to egrep as now we plan on using regex which works well with egrep or you can use "grep -E"
Here -o means "Print each match, but only the match, not the entire line."
I hope the article was useful.