tags:

views:

152

answers:

5

fgrep -ircl --include=*.{sql} "[--]" * doesn't seem to be doing the trick. Please help...

Thanks for the responses guys. I am trying to replace the '--' with '#' and am having a tough time. I created a new question here. If you could help, that had be awesome.

+1  A: 

You need to escape dash characters inside square brackets, which are used to represent ranges inside a character class ([a-z] for example). In this case, however, you don't need to use square brackets to match a literal string.

Finally, -- is a speical sequence that causes argument parsing to stop. To include a literal -- as an argument, you'll have to explicitly stop argument parsing:

fgrep -ircl --include=*.{sql} -- -- *
meagar
Escaping inside a character class isn't going to change the meaning, though.
calmh
+4  A: 

That looks like a regular expression character class matching the (single) - character. The string -- is commonly used to indicate "no more parameters follow", so perhaps you should try

fgrep -ircl --include=*.{sql} -- -- *

that is "end of parameters" followed by the actual string you want to search for.

calmh
Strangely enough, it works without --include=*.{sql} .. any ideas?
ThinkCode
@NJTechie If you omit the `--include`, then all files/sub-directories in the current directory will be searched, as you're passing them as arguments. That's what the final `*` does - matches all files in the current directory.
meagar
+1  A: 

Dash characters can only be in the first position in brackets [] because they indicate a range [a-z] or [0-9]. You could do [-][-].

Adam Ruth
They can also be last. :)
calmh
just using grep [-][-] works but not with fgrep :(
ThinkCode
@calmh - I did not know that, thanks.
Adam Ruth
A: 

Try using single quotes '[--]' instead of "[--]"

fgrep -ircl --include=*.{sql} '[--]' *
armandino
+1  A: 

If you want to fgrep all files that end with .sql then use

fgrep -ircl --include=*.sql -- -- *

or (note the comma in {sql,}:

fgrep -ircl --include=*.{sql,} -- -- *

If you want to fgrep more than one type of extension, then use something like

fgrep -ircl --include=*.{sql,txt} -- -- *

As others have already mentioned, the first -- tells fgrep to stop looking for flags and options. The second -- is the fixed-string pattern.

unutbu