How to find what does not contain with grep in linux

WBOY
Release: 2022-05-17 16:51:58
Original
10769 people have browsed it

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
Copy after login

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
Copy after login

or

grep -v "OK" result |wc -l
Copy after login

Display rows that do not contain ok and the number of rows

grep -nv "OK" result
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template