I am looking for the literal string ->foo in all the *.cpp files in a single directory. If I try
grep -F "->foo" *.cpp
grep reports
Invalid option -- '>'
Then, if I try
grep -F "-\>foo" *.cpp
I get
Invalid option -- '\'
How can I get this working?
Generally (not grep specific) using -- signifies the end of options:
grep -F -- "->foo" *.cpp
Helpful when you accidentally create files starting with -:
$ touch -- -damn
$ ls -- -*
-damn
$ rm -damn
rm: invalid option -- 'd'
$ rm -- -damn
Try this:
grep -e "->foo" *.cpp
From the man page:
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX .) [emphasis added]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With