using grep when the pattern contains a !
I am try to search for a pattern using grep. The problem is that the pattern sometimes contains a !. This seems to mess grep up and call the last command entered into the console. How can I get it to stop doing this? It is important that I have the ! in the search. Please help!
Thanks, farmerjoe |
If the search phrase is a static string, try simple escaping the excl point, as:
Code:
find . -type f -exec grep -H "\!" '{}' ';' If it's a variable string, you can do variable replacement using a replacement expression. |
And if you're not using find, it's basically the same, but this may make things clearer:
[code] grep "\!regexp" files |
Ah! stupid me! i thought i had tried that earlier but i guess i didnt do it correctly! Thanks for the help guys!
-farmerjoe |
Hmm..heres another question:
Before i run the grep command. I am going to need to convert my expression to one that will work if it has ! in it. I have tried echo "$EXPRESSION" | sed -e 's/!/\\!/g' but that doesnt work because echo has the same problem that grep did. Any tips? -farmerjoe |
Code:
#!/bin/bash Code:
~> ./q.sh |
ahhhh. i see. thanks! didnt know i could do that!
-farmerjoe |
HMm.. How would i do this with a ' ?
I've tried this but it doesnt seem to work: START="This is'nt a test!" PRE=${START//\!/\\\!} echo "pre: $PRE" POST=${PRE/\'/\\'} echo "post: $POST" |
Ooops! figured it out!
-farmerjoe |
Quote:
Code:
SF1B : /supmis/soumen/tmp > cat excl.sh HTH. |
All times are GMT -5. The time now is 10:20 PM. |