How to grep two strings and words

What command I need to use to search for two strings such as ‘containerSciFilter’ and ‘backgroundProcessorDelay’ in a Linux server? I need to use grep as file is huge.

You can grep two strings and words easily using the following syntax

grep -E 'string1|string2' filename
egrep 'word1|word2' /path/to/file

Grepping two strings / words

grep -E 'containerSciFilter|backgroundProcessorDelay' /path/to/config.file

Make it case insensitive search so that it will match both upper and lower case (or combination of both) words/strings by passing the -i:

egrep -i 'containerSciFilter|backgroundProcessorDelay' /path/to/config.file

Restrict search to marching words only:

egrep -i -w 'containerSciFilter|backgroundProcessorDelay' filenme

Where,

  1. -i : ignore case distinctions in patterns and data
  2. -w : match only whole words
  3. -E : PATTERNS are extended regular expressions

Take a look at my guide:

1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki