Vivek
Vivek

Reputation: 4662

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

Upvotes: 0

Views: 121

Answers (2)

pvg
pvg

Reputation: 2729

pipe the whole thing through grep -v 'exclude pattern'

Upvotes: 0

mathematical.coffee
mathematical.coffee

Reputation: 56935

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

Upvotes: 3

Related Questions