need help with UNIX text search command

need help with UNIX text search command

Post by bmeye.. » Wed, 15 Dec 1999 04:00:00



Hi all,
I hope someone can help with this problem:

On Solaris 2.6 I am connected to the server from a PC via telnet.  I
need to be able to do a recursive text search.  Sounds simple, but none
of the commands I have tried, or others have suggested, mainly various
combinations of  find  and  grep, have worked.  In effect, what I need
is a
grep -R
but unfortunately that's not one of the options.

I know the CDE on the console will get me this info thru the GUI
interface, but I need to be able to do it via telnet.  I also know that
others here with Sun workstations can do it via their GUI interface,
but I am on a PC, so I need to be able to do it via command line.

I am not looking for file NAMES, but file CONTENTS.

Any suggestions??

TIA,
Brian
Brian Meyette
Oracle Applications DBA

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

 
 
 

need help with UNIX text search command

Post by giaco » Wed, 15 Dec 1999 04:00:00


#!/bin/ksh

#useage:  recursive_grep.ksh TARGET_STRING DIR

TARGET_STRING=$1
DIR=$2

for FILE in $(find $DIR)
do            
  if [[ ! -d $FILE ]]; then
     echo "In $FILE:\n"
     grep $TARGET_STRING $FILE
  fi
done      

Quote:>Hi all,
>I hope someone can help with this problem:
>On Solaris 2.6 I am connected to the server from a PC via telnet.  I
>need to be able to do a recursive text search.  Sounds simple, but none
>of the commands I have tried, or others have suggested, mainly various
>combinations of  find  and  grep, have worked.  In effect, what I need
>is a
>grep -R
>but unfortunately that's not one of the options.
>I know the CDE on the console will get me this info thru the GUI
>interface, but I need to be able to do it via telnet.  I also know that
>others here with Sun workstations can do it via their GUI interface,
>but I am on a PC, so I need to be able to do it via command line.
>I am not looking for file NAMES, but file CONTENTS.
>Any suggestions??
>TIA,
>Brian
>Brian Meyette
>Oracle Applications DBA
>Sent via Deja.com http://www.deja.com/
>Before you buy.


 
 
 

need help with UNIX text search command

Post by Shiv » Thu, 16 Dec 1999 04:00:00


grep your_string `find your_start_directory -type f -print`


> Hi all,
> I hope someone can help with this problem:

> On Solaris 2.6 I am connected to the server from a PC via telnet.  I
> need to be able to do a recursive text search.  Sounds simple, but none
> of the commands I have tried, or others have suggested, mainly various
> combinations of  find  and  grep, have worked.  In effect, what I need
> is a
> grep -R
> but unfortunately that's not one of the options.

> I know the CDE on the console will get me this info thru the GUI
> interface, but I need to be able to do it via telnet.  I also know that
> others here with Sun workstations can do it via their GUI interface,
> but I am on a PC, so I need to be able to do it via command line.

> I am not looking for file NAMES, but file CONTENTS.

> Any suggestions??

> TIA,
> Brian
> Brian Meyette
> Oracle Applications DBA

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

--
regards,
Shiva

http://www.slack.net/~shiva/

 
 
 

1. Need unix command/script to recursively search

It might not be earth shattering, but I use a ksh function (in .profile or whatever)
that I called igrep:

  igrep foo
    Find all "foo"s in "*.h" files starting "/usr/include"

  igrep foo /etc "*.conf"
    Find all "foo"s in "*.conf" files starting "/etc". note quoting!

----snip-snip------

function igrep {
# My own variant of grep to find an expr in a hierachy
# of directories. The default is to find an expression in all
# *.h header files under /usr/include. The extra functionality
# is the sub-directory recursion. To do it with grep would need:
# grep foo /usr/include/*.h /usr/include/*/*.h /usr/include/*/*/*.h
# As the "/" and "." are treated specially by ksh filename expansion.
        if [[ ($# -lt 1) || ($# -gt 3) ]]; then
                print "Usage: $0 <search-expr> [ <start-dir> ] [ <file-list> ]"
                return 1
        fi
        files=${3:-'*.h'}
        dirs=${2:-'/usr/include'}
        print "finding $1 in files $files starting $dirs"
        grep $1 `find $dirs -name $files -print`

----snip-snip------

+-------------------------------------------------------------+

| Alcatel Bell Telephone,    phone: +32 3 829 5130            |
| Space Dept. RS31,          fax:   +32 3 829 5502            |
| Berkenrodelei 33,                                           |
| 2660 Hoboken, Belgium.                                      |
+-------------------------------------------------------------+

2. Elitegroup PCI board - anybody

3. Need help with a file command to search for files

4. ANNOUNCEMENT: Garlic, free mol. visual.

5. HELP!! need grep command that search all directories !

6. isapnp for aha152x

7. help needed - grep command line - searching for binary hex chars in a xml file

8. ulimit

9. HELP!! need grep command that search all directories !

10. Search and replace text in a bunch of text files..

11. Search and replace text in a bunch of text files

12. Need Help: converting LF, CR for text file between UNIX and DOS

13. Solaris 2.6: unix command to search binaries for char string portion (not null terminated