2
I'm trying to pass -- as an argument to grep because the file I'm interested in contains -- within its text, like so
grep -- file.txt
but I cannot because grep sees -- as a flag. How do I pass -- as an argument, rather than a flag, to grep?
2
I'm trying to pass -- as an argument to grep because the file I'm interested in contains -- within its text, like so
grep -- file.txt
but I cannot because grep sees -- as a flag. How do I pass -- as an argument, rather than a flag, to grep?
1
grep -e '--' file.txt
From the man page for grep:
-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.)
0
At least with GNU grep you can tell it that no more flags are forthcoming with --
. You can test it like this with a recent version of bash:
<<<"--" grep -- --
Output:
--
whad does <<< do? – MYV – 2013-05-28T03:23:01.090
@Maksim: It's the same as saying
echo --
, but lets the shell handle it and avoids portability issues. – Thor – 2013-05-28T09:45:38.440