简体   繁体   中英

Exclude a pattern from grep result

I use below command to search for a specific text in a directory and its sub-directories.

find . -exec grep -i -n -w 'search text' /dev/null {} \\;

Result is displayed in below format ./directory/filename:<line_number>:<matching text>

I want to exclude all lines with /* from the result.

How to do this?

OS Version: Sun OS 5.10

You could pipe the result through grep again, filtering out matches of /* :

find . -exec grep -i -n -w 'search text' /dev/null {} \; | grep -v '/\*'

where grep -v returns lines that don't match (and I'm assuming you mean a literal /* hence the regex).

通过grep -v'排除模式'传递整个内容

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM