I tried to use the grep command to search for a string like -R in a file. But the command thinks, that I am trying to hand over an option like -i for ignore case.
Asked
Active
Viewed 173 times
-1
Rui F Ribeiro
- 56,709
- 26
- 150
- 232
Adrian
- 1
3 Answers
3
The -e option for grep is for explicitly saying "the next argument is the pattern":
grep -e -R file
The above would search for line matching -R in the file called file.
The -e option may occur multiple times on the command line, and grep will use all the given patterns (you will get the lines back that matches any of the patterns).
Kusalananda
- 333,661
2
As well as the previously mentioned answers, -- is used to signify the end of options, allowing you to use patterns afterward that may resemble an argument without being interpreted undesirably:
$ echo -R | grep -- '-R'
-R
jesse_b
- 37,005
"-R", not-R– jsotola Jun 09 '19 at 21:58grep -e -R ./-file1 file2, where-Ris a pattern starting with-, and./-file1is a filename starting with-. – Jun 09 '19 at 21:59