[olug] Unix Tip: FINDING A STRING

Trent Melcher tmelcher at trilogytel.com
Tue Nov 19 19:58:14 UTC 2002


Note -H only works in the GNU grep.  Solaris and SCO don't have this option.
Don't know about HP-UX.
Also just checked BSD, some versions do, some don't.

Check your *nix Flavor to be certain.

Trent

-----Original Message-----
From: olug-admin at olug.org [mailto:olug-admin at olug.org]On Behalf Of
Jeremy Bettis
Sent: Tuesday, November 19, 2002 1:18 PM
To: olug at olug.org
Subject: RE: [olug] Unix Tip: FINDING A STRING


A more direct version of the same thing would be:

find . -type f -exec grep -H "string" {} \;

Or if you don't want the lines, just the filenames

find . -type f -exec grep -q "strig" {} \; -print
--
Jeremy Bettis, Software Development Manager
HKS Medical Information Systems, Inc.
jeremyb at hksys.com


> -----Original Message-----
> From: Unix Guru Universe [mailto:listserv at ugu.com]
> Sent: Tuesday, November 19, 2002 1:03 PM
> To: olug at olug.org
> Subject: [olug] Unix Tip: FINDING A STRING
>
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> 			      UNIX GURU UNIVERSE
> 			         UNIX HOT TIP
>
> 			Unix Tip 2149 - November 19, 2002
>
> 		    http://www.ugu.com/sui/ugu/show?tip.today
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
> FINDING A STRING
>
> How to find a string somewhere on the system.  Many times we are
> called to search for a string, but we have no idea where it may
> be lurking.  Judicious use of the find and grep commands will
> make you a hero with your co-workers.
>
> # find . -type f -exec grep "string or options" /dev/null {} \;
>
> Normally using only:
> # find . -type f -exec grep "string/options" {} \;
>
> Produces the target string, but you will have no clue as to where
> it is located, making this almost as frustrating as using windoze!
> Remember when grep'ing against multiple files the filename will be
> listed before the match.
>
> $ grep there *
> foo:I found the target here
> bar:You are there
>
> In our find command we use /dev/null as a file to search against,
since
> we know the search will always fail if the string is found in "{}"
there
> filename is printed.  To borrow from a famous quote:
> "Pretty tricky sis!"
>
> This tip generously supported by: james_b_horwath at glic.com
>
>
>
------------------------------------------------------------------------
--
> To Subscribe:    http://www.ugu.com/sui/ugu/show?tip.subscribe
> To Unsubscribe:  http://www.ugu.com/sui/ugu/show?tip.unsubscribe
> To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today
>
>
========================================================================
==
> DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND
ARE
> NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE
UNIX
> GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU  ADVISES THAT
> ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.
>
> Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
>
========================================================================
==
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
_______________________________________________
OLUG mailing list
OLUG at olug.org
http://lists.olug.org/mailman/listinfo/olug





More information about the OLUG mailing list