escapeing the characters '[' and ']' in grep
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 ? TIA |
Does
Code:
grep -e "array\[[0-9][0-9]\]" test.c |
some other solutions:
Code:
grep 'array\[[0-9]\{2\}\]' file 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. |
Thanks a lot titopoquito.
@Muha: thanks for that tip '{2}'. That was helpful.. |
All times are GMT -5. The time now is 09:27 PM. |