How to grep for string "->"
It seems easy, but I can't seem to do a `grep "->" input`. I would like to be able to do this within backticks in perl where the input for grep is stored in a variable $variable or @variable e.g. `@variable | grep "->"`.
The error I am currently getting is because no matter how I specify ->, grep thinks I am trying to specify the option -> which is, of course, not valid. EDIT: I found that in my case, I only needed to use ">", however, I am still interested in how to grep for a pattern starting with a "-". Also, whenever I use @variable within backticks in perl, even if I follow it with a pipe, it tries to execute all the lines of that variable as commands instead of piping them to the grep/awk/etc. |
grep -e '->'
the -e means that the next argument is the pattern, and won't be interpreted as an argument. |
remember, you can always use a backslash in unix
to fix such stuff, Code:
grep \-\> file post what you are trying to do. |
For whatever reason, grep takes \- as an argument just as much as it takes - or "-". So the example you posted:
Code:
grep \-\> file Code:
grep: invalid option -- '>' Code:
echo This is a & test Code:
echo This is a \& test |
OK, so...
What I have gleaned is: The backslash is interpreted by the shell as escaping the next character, which then gets passed literally to the program (without the backslash). So: Code:
# Both the '-' and '>' are escaped in the shell, but the '-' is passed unescaped |
oops
grep '\-\>' file |
All times are GMT -5. The time now is 03:38 AM. |