0

So am trying to run unix clang --help | grep -f command to get a list of lines in clang help which contain text "-f". Clearly this does not do the job, because grep thinks -f is an option for him instead of thinking that is the pattern to search for.

The question is: how do I search for patterns which start with dash?

Serid
  • 354
  • 6
  • 13

2 Answers2

2

The common way to do this is by having the option -- after all the "real" arguments that start with dashes, and then grep will know that the other ones aren't options.

So for example, if you wanted to grep for -f but do it case-insensitively, you'd do grep -i -- -f.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
1

Just use \\-f

$ ls --help | grep \\-f
  -f                         do not sort, enable -aU, disable -ls --color
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
      --full-time            like -l --time-style=full-iso
      --group-directories-first
                               file-type (--file-type), classify (-F)
Gellweiler
  • 751
  • 1
  • 12
  • 25