Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep for a string containing a bracket?

Status
Not open for further replies.

cmayo

MIS
Apr 23, 2001
159
US
I'd like to grep a collection of PHP scripts for an array variable called, in this case, $year[x]. Lots of script have $year variables, but I'm only interested in the arrays, so I'd like to find '$year['. Grep is pretty hard to get along with, though, when I'm trying to find a string that includes a bracket, escaping it (\$year\[) doesn't seem to help, and you'd be surprised at how many Google hits for "grep string bracket' turn up exactly the wrong results.

Anybody know how I can do this?

TIA
 
Also an awk solution:

Code:
awk '/\$year\[/' script.php

Regards,
Chuck
 
Thanks Chuck - both those guys worked like a charm!
 
You could also just use [tt]fgrep[/tt]. It only pattern matches on the exact string you give it. That's why it's "Fast Grep".
Code:
fgrep '$year[' script.php
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top