How to Use egrep to Find Multiple Strings in a File?

Below is the example to find multiple strings in a file using the egrep command in Linux or Unix environment.

egrep Command to Find Multiple Strings in a File

In the following example, the egrep command will look for strings Scott, Smith and Phillip in all text files.
egrep 'Scott|Smith|Phillip' *.txt

Output:

emp.txt:1200|Scott|Technology|5500
emp.txt:9500|Smith|Technology|6000
emp.txt:9548|Phillip|IT|8000

To specify a particular file, you can specify the name instead of *.txt. For example:
egrep 'Scott|Smith|Phillip' emp.txt

egrep command example to search multiple patterns in a file in shell.

Comments

Popular posts from this blog

How To Write Query in Toad for Oracle?

How to Kill Session in Toad for Oracle?

How to Change Password in Toad for Oracle?