views:

137

answers:

4

I want to grep for the string "-X" in a file but it's confusing this as a command line argument.

I've tried

grep "-X"
grep \-X
grep '-X'
+1  A: 

grep -e -X will do the trick.

Thomas
my grep doesn't have -e, very weird
Mike
solaris for the lose
Mike
Available on solaris from /usr/xpg4/bin/grep, btw. Lots of more-complete utilities in that directory.
pra
+2  A: 

how about

grep -- "-X"

newacct
`--` is a handy trick for a number of Unix utilities.
Johnsyweb
A: 

I dont have access to a Solaris machine, but grep "\-X" works for me on linux.

ezpz
A: 

you can use nawk

$ nawk '/-X/{print}' file
ghostdog74