i have used the grep command very effectively in the past. But right now i am facing a problem..
I want to find this string 'array[25]' in a text file.
i used:
grep 'array[[0-9]+]' test.c
grep 'array\[[0-9]+\]' test.c
grep array[[0-9]+] test.c

all dont seem to work as it does not show proper results.
How do i escape these special characers '[' and ']' ?
or for that matter how do i make grep work for this case ?

{2} specifies the number of repeats of [0-9]
fgrep matches literal strings so you can't use regexp.
egrep uses extended regular expressions. So you can use the +
+ means one or more and is analogous to \{1,\} which is a regular expression so we can use that in grep in the last example.

logicalfuzz

03-21-2006 03:04 AM

Thanks a lot titopoquito.
@Muha: thanks for that tip '{2}'.
That was helpful..