Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use grep or grep not operator in linux?


Asked by Jordyn Zuniga on Dec 04, 2021 Linux



7 Linux Grep OR, Grep AND, Grep NOT Operator Examples 1 Grep OR Using \| If you use ... 2 Grep OR Using -E grep -E op ... 3 Grep OR Using egrep egrep i ... 4 Grep OR Using grep -e Using ... 5 Grep AND using -E ‘pattern1 ... 6 Grep AND using Multiple gre ... 7 Grep NOT using grep -v
In addition,
The Linux grep command is a string and pattern matching utility that displays matching lines from multiple files. It also works with piped output from other commands. We show you how. The grep command is famous in Linux and Unix circles for three reasons. Firstly, it is tremendously useful.
Thereof, There is no grep AND opearator. But, you can simulate AND using patterns. The examples mentioned below will help you to understand how to use OR, AND and NOT in Linux grep command. The following employee.txt file is used in the following examples.
Also Know,
There is no AND operator in grep. But, you can simulate AND using grep -E option. grep -E 'pattern1.*pattern2' filename grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename. The following example will grep all the lines that contain both “Dev” and “Tech” in it (in the same order).
Moreover,
Grep NOT using grep -v Using grep -v you can simulate the NOT conditions. -v option is for invert match. i.e It matches all the lines except the given pattern. For example, display all the lines except those that contains the keyword “Sales”. You can also combine NOT with other operator to get some powerful combinations.