Djanym
Djanym

Reputation: 342

Search for a pattern in files with outputing the result

How to search for a pattern in files in a directory with:

  1. .php files
  2. output the matched line

I'm trying like this:

grep -lir "eval" --include '*.php' ./

But it's not enough.

Second part

Also, a second part that I want to search in php code only. So it means the matched pattern should be after <? and not after ?>.

Upvotes: 0

Views: 117

Answers (1)

Barmar
Barmar

Reputation: 780673

I think this will do it:

find . -type f -name '*.php' -exec awk '/<\?/,/\?>/ && /eval/' {} \;

/<\?/,/\?>/ specifies the range of lines between <? and ?>.

Upvotes: 2

Related Questions