Home  >  Article  >  Operation and Maintenance  >  How to find what does not contain with grep in linux

How to find what does not contain with grep in linux

WBOY
WBOYOriginal
2022-05-17 16:51:5810667browse

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".

How to find what does not contain with grep in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to find strings that do not contain strings in grep in Linux

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn