I am trying to recursively find some pattern which contains meta character.

Pattern that I searching for is template <int N>

I have tried :

grep -F -lir "template <int N>"  *    # trying to find "template <int>"
                                      # -F treat meta char as normal char

I get:

     grep: \<int: No such file or directory   
     grep: N\>: No such file or directory

closed as off-topic by Kusalananda, Jeff Schaller, don_crissti, Stephen Kitt, dhag Jul 26 '16 at 20:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Kusalananda, Jeff Schaller, don_crissti, Stephen Kitt, dhag
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Are you sure that's exactly the command you gave? The way you present it, with the quotes, works for me. – ilkkachu Jul 23 '16 at 21:50
  • @ilkkachu Yes .. I am using OSX – pokche Jul 23 '16 at 21:57
  • So that's the reason. Mate, things are a bit a bit different on OS X. I think you need to read this article. I hope it helps. – FarazX Jul 23 '16 at 22:09
  • What shell are you running this in? It work for me on OS X in bash, ksh, tcsh and csh. – Kusalananda Jul 23 '16 at 22:12
  • 1
    @Kusalananda So I had posted the problem in grep bug report and turns out it not a bug and was my fault. I had edited my .profile file to make sure grep defaults to --color=auto by doing /usr/bin/grep --color=auto $* and this was the problem. I should have done /usr/bin/grep --color=auto "$@" after this the problem disappears. – pokche Jul 26 '16 at 15:32

Try using fgrep (or the -F option to grep that does the same), and write your query without escaping the "<" and ">". I'd also suggest using single-quotes ' rather than double-quotes ", since the shell may expand what it think is variables and such when you use double-quotes.

fgrep -i 'template <int N>' *

  • @Baard Kopperud : When I do fgrep -lirE 'template <int N>' * --exclude-dir={dir1} : It cannot find the file. I do have a file with that pattern but that file does not show up – pokche Jul 23 '16 at 21:48
  • fgrep -E feels a bit redundant. GNU grep even complains about it. – ilkkachu Jul 23 '16 at 21:55
  • @don, exactly. I'm off to sleep. – ilkkachu Jul 23 '16 at 21:57
  • apparently When I use grep -F problem happen but when I use fgrep the problem vanishes – pokche Jul 23 '16 at 22:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.