Home >Operation and Maintenance >Linux Operation and Maintenance >How to find what does not contain with grep in linux
In Linux, you can use the "-v" parameter of the grep command to find strings that do not contain To select, display all lines that do not contain matching text, the syntax is "grep -v does not contain string filename".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
The Linux grep command is used to find strings that meet the conditions in the file.
The grep command is used to find files whose content contains the specified template style. If the content of a file is found to match the specified template style, the default grep command will display the column containing the template style. If no file name is specified, or if - is given, the grep command reads data from the standard input device.
[root@www ~]# grep [-acinv] [--color=auto] '搜寻字符串' filename
Options and parameters:
-a: Search binary files as text files
-c: Calculate the number of times the 'search string' is found
-i: Ignore the difference between upper and lower case, so the upper and lower cases are treated as the same
-n: Output the line number by the way
-v: Reverse selection, that is Show the line without 'search string' content! Display all lines that do not contain matching text
--color=auto: You can display the found keywords in color!
For example, I need to extract rows that do not contain ok and count the number of corresponding rows
grep -cv "OK" result
or
grep -v "OK" result |wc -l
Display rows that do not contain ok and the number of rows
grep -nv "OK" result
Recommended learning: Linux video tutorial
The above is the detailed content of How to find what does not contain with grep in linux. For more information, please follow other related articles on the PHP Chinese website!