Grep question

Grep question

Post by waw.. » Thu, 23 Mar 2000 04:00:00



I need help with grep.  A korn shell script I'm modifying uses a grep
with a -e option.  The grep on our solaris 2.6 workstation does not
list -e as an option.  In over versions of grep, what does the -e
option do.  WHat equivalent do I use in Solaris?

Here is example code:
  grep -e Error -e Warning $logfiles

Should I be using egrep?

Thanks,
  Randy

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Grep question

Post by Barry Margoli » Fri, 24 Mar 2000 04:00:00



>I need help with grep.  A korn shell script I'm modifying uses a grep
>with a -e option.  The grep on our solaris 2.6 workstation does not
>list -e as an option.  In over versions of grep, what does the -e
>option do.  WHat equivalent do I use in Solaris?

RTFM:

  /usr/xpg4/bin/grep
     The following options are supported  for  /usr/xpg4/bin/grep
     only:

     -e pattern_list
                    Specify one or more patterns to be used  dur-
                    ing   the  search  for  input.   Patterns  in
                    pattern_list must be separated by  a  NEWLINE
                    character.   A  null pattern can be specified
                    by  two  adjacent   newline   characters   in
                    pattern_list.   Unless the -E or -F option is
                    also specified, each pattern will be  treated
                    as  a  basic regular expression.  Multiple -e
                    and -f options are accepted by grep.  All  of
                    the specified patterns are used when matching
                    lines,  but  the  order  of   evaluation   is
                    unspecified.

GNU grep also supports this.

Quote:>Here is example code:
>  grep -e Error -e Warning $logfiles

>Should I be using egrep?

You could:

egrep 'Error|Warning' $logfiles

But if you needed to protect patterns beginning with '-', you would have to
use a version of grep that supports -e.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Grep question

Post by Douglas Stetn » Fri, 24 Mar 2000 04:00:00




>>Here is example code:
>>  grep -e Error -e Warning $logfiles

>>Should I be using egrep?

>You could:

>egrep 'Error|Warning' $logfiles

>But if you needed to protect patterns beginning with '-', you would have to
>use a version of grep that supports -e.

Not  true (even  though  it does  not appear  that  he needs  patterns
beginning with '-' from the above).

egrep -- '-pattern|other_pattern' filename

will work just fine.

--
Douglas G. Stetner                  Senior UNIX Support Engineer

My opinions are my own              Wollongong, Australia

 
 
 

Grep question

Post by Ken Pizzi » Fri, 24 Mar 2000 04:00:00


On 23 Mar 2000 01:07:10 GMT,



>>But if you needed to protect patterns beginning with '-', you would have to
>>use a version of grep that supports -e.

>Not  true (even  though  it does  not appear  that  he needs  patterns
>beginning with '-' from the above).

>egrep -- '-pattern|other_pattern' filename

>will work just fine.

Well, that presumes that your egrep understands the "--" option,
which isn't true for 15-year old versions of egrep.

The use of a leading hyphen in an RE actually isn't a problem
for either egrep or plain grep:
  egrep '(-)pattern|other_pattern' filename
and
  grep '[-]pattern' filename
both work just fine.  (Yes, the grep approach would also work
with egrep; I just wanted to show different mechanisms.)

The "-e" option to fgrep is older than the use of "--" to
terminate option processing, so I'd be a little suprised if one
had an implementation of [ef]?grep which understood "--" but
not "-e".

                --Ken Pizzini

 
 
 

1. grep question New to grep

How do I display file names having ".html" extension and do not start
with letters "d" to "p" from /usr directory using grep utility?

Second question is:
How do I find the number of files that contain "period" (.) in their
names in /usr/home directory using grep?

Third question is How to find a total number of files in /usr
directory using grep?

Thanks for any help

Wesley

2. Compaq Presario 1200Z - Lockup on install

3. grep question

4. Pseudo device failure

5. linswap: LinkExchange for Linux, GPL, BSD apps ..... read ...

6. a stupid Grep question (but can you ANSWER it?)

7. Portsentry

8. grep question..

9. find + grep Question

10. another grep question

11. Grep Question

12. stupid grep question