I have a file with the below contents:
sh-4.2$ cat file1
example of multiple
pattern
this is an
example of multipole
sorry multiple
pattern matching
using grep
so the example is the
file itself
-example
-multiple
-bye
tata
!
While searching for "-example" in the above file, the grep command is not giving the desired output. I know if the pattern contains '-' then -e option should be used:
In the first example I used -example directly without any quotes:
sh-4.2$ grep -example file1
example of multiple
example of multipole
so the example is the
-example
-example with single quotes:
sh-4.2$ grep '-example' file1
example of multiple
example of multipole
so the example is the
-example
-example with double quotes and escape characters
sh-4.2$ grep "\-example" file1
-example
sh-4.2$