0

I'm looking through a couple hundred files looking for the following string:

$v1=Name($v2[x1].$v3[x2].$v4[x3].$*v5[x4].)

grep -HREln "(x1)" . > foo
find . -type f | xargs grep -l 'x1' > foo

However the variable x1 changes from file to file. What I would like to do is search for the pattern:

$*=Name($*[*].$*[*].$*[*].$**[*].) 

regardless of the variable or white spaces. any assistance would be great.

PsiX
  • 1,557
  • 1
  • 17
  • 33
  • Take a look: [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/3776858) – Cyrus Dec 03 '15 at 18:49

1 Answers1

1

Change every * to .*, put \ before every $, [, ], or literal ., and you're there!

find . -type f |
  xargs grep -l 'Name(\$.*\[.*\]\.\$.*\[.*\]\.\$.*\[.*\]\.\$.*\[.*\]\.)' > foo

Note: this will miss variations that span multiple lines, and does not take whitespace into account at all.

webb
  • 3,358
  • 1
  • 10
  • 21