It is currently Mon, 25 Sep 2023 10:42:23 GMT



 
Author Message
 Q: Bizarre grep problem
I recently wanted to find all ocurrences of the string '-in2' in a selection
of source files. Naturally enough, I decided to use

                                grep '-in2' *

but instead of the expected output, I got

                                grep: illegal option -- 2

followed by the usuage template. Eh? Can anyone tell me whats going on?
I guess it has something to do with the `-', but as it is inside the quotes
it shouldn't do, should it? Any help would be gratefully received!

Oh, if it makes any difference, I am using csh (interactively only :) on an
alpha box running OSF/1 v3.2.

Cheers...

========================= john.en...@bbsrc.ac.uk =====================///===



 Tue, 12 May 1998 03:00:00 GMT   
 Q: Bizarre grep problem

john>                                grep '-in2' *

john>                                grep: illegal option -- 2

What does "-" mean to UNIX programs?  It introduces an
option (list).

You are therefore saying "run grep with flags -i -n and -2"

"-2" is not a grep option.

If you want to look for a pattern/string beginning with "-"
then you have to tell grep that this is the start of the
pattern argument, i.e.

     grep -e '-in2' *

should all be in the manpage...
tony



 Tue, 12 May 1998 03:00:00 GMT   
 Q: Bizarre grep problem
: I recently wanted to find all ocurrences of the string '-in2' in a selection
: of source files. Naturally enough, I decided to use
:                               grep '-in2' *
: but instead of the expected output, I got
:                               grep: illegal option -- 2
: followed by the usuage template. Eh? Can anyone tell me whats going on?
: I guess it has something to do with the `-', but as it is inside the quotes
: it shouldn't do, should it? Any help would be gratefully received!
: Oh, if it makes any difference, I am using csh (interactively only :) on an
: alpha box running OSF/1 v3.2.
: Cheers...

This has now been solved. Thanks to all who emailed me. :*) FWIW, the problem
arose because although the quotes stop the shell getting upset,  they are
removed by grep, so grep thought -in2 was an option list, hence the error.
So there you go. :^)

========================= john.en...@bbsrc.ac.uk =====================///===



 Tue, 12 May 1998 03:00:00 GMT   
 
   [ 3 post ] 

Similar Threads

1. Bizarre messages from grep on DOS files

2. tail | grep | grep | grep


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software