[SunHELP] Grep Help

Magnus Abrante sunhelp at sunhelp.org
Wed Sep 19 10:05:00 CDT 2001


egrep "pattern|other_pattern|something_else" /path/to/file

For example:
dak-01(/etc):$ egrep "telnet|ftp|nfs" services 
ftp-data        20/tcp
ftp             21/tcp
telnet          23/tcp
tftp            69/udp
nfsd            2049/udp        nfs             # NFS server daemon (clts)
nfsd            2049/tcp        nfs             # NFS server daemon (cots)
dak-01(/etc):$ 

or if you want to use ordinary grep you could always do something like
this if you are using sh or bash:

for i in pattern other_pattern yetanotherpattern; do grep $i <file>; done

Talking about recursive greps btw;
One method to do recursive grep which was forgotten in this thread (i think)
is to do: grep "pattern" `find . -type f` ;-)

Hope it helps,

        //Magnus Abrante
/* This is my opinion and not the one of my employer */

On Wed, Sep 19, 2001 at 02:56:44PM -0400, Shain Miley wrote:
> In this instance I do not need to go into subdirectories, there is only
> one file that I will be looking at.  I am looking for a way to search
> one file for many many things.  I thought that pattern list was what
> I was looking for but now I am unsure.
> 
> Shain
> 
> 
> "Fogg, James" wrote:
> 
> > I highly recommend rgrep (recursive grep), esp. since it can search
> > subdirectories.
> >
> > > -----Original Message-----
> > > From: Shain Miley [mailto:smiley at tvdata.com]
> > > Sent: Tuesday, September 18, 2001 6:52 PM
> > > To: sunhelp at sunhelp.org
> > > Subject: [SunHELP] Grep Help
> > >
> > >
> > > Hi,
> > > I need to search for about 15 things (list of ip addresses
> > > and hostnames) in a file useing grep.  Do I have to use grep
> > > 15 different times or can I give
> > > multiple search options to one grep command?  I tried 'grep
> > > 'a b c d e' file' but I get an error:   grep: RE error 41: No
> > > remembered search string.  Any
> > > ideas?  i have tried using examples I found on the web but it
> > > looks like that does an exact search or something other than
> > > what I need.  Thanks.
> > >
> > > Shain
> > >
> > > _______________________________________________
> > > SunHELP maillist  -  SunHELP at sunhelp.org
> > > http://www.sunhelp.org/mailman/listinfo/sunhelp
> > >
> > _______________________________________________
> > SunHELP maillist  -  SunHELP at sunhelp.org
> > http://www.sunhelp.org/mailman/listinfo/sunhelp
> 
> _______________________________________________
> SunHELP maillist  -  SunHELP at sunhelp.org
> http://www.sunhelp.org/mailman/listinfo/sunhelp



More information about the SunHELP mailing list