[Solved] Finding a word in all shell scripts

Hi i have to find the shell script that contain the word

PROC__TO_UPDATE

SEARCH SHOULD BE INSENSITIVE AND SCRIPT CAN BE DEPLOYED IN ANY PATH.

I am on Solaris.

Hello,

Could you please be more specific in your requirement. Also please don't use capital letters while posting.

Thanks,
R. Singh

What about:

find / -exec grep -l "word_to_search" '{}' ';'

Hi Ravinder,
Ok.:b:

I am looking to find the word say "abcd" (they may be in small or capital letters)
in the .sh file.i want to display the name of the file along with the absolute path.

Something like

grep -i "abcd"  *.sh

---------- Post updated at 06:39 PM ---------- Previous update was at 06:36 PM ----------

Is your search case insensitive?
I guess not

Depends. If you wish the word you are looking for to be case insensitive add -i switch to grep command. Find is case insensitive as this very command will find every single file no matter what name it has got.

like this

find / -exec grep -l -i "word_to_search" '{}' ';'

You mean to say -i is redundant here since find command is insensitive?
But find will be insensitive for FILE NAMES not its content right?

Plu i only want to search in .sh files

Exactly. Find does not consider content of the files at all. It just merely finds a file accordingly to condition. In this case we have no condition given so every file would do and for every one of them it runs that grep. -i switch is telling it not to care about case sensivitivity and -l just prints every file name that contains given string. Is that what you were looking for?

Ok Thanks.
So ican execute your command any path and it will give all the file names?

Your code is not working actually.
Its not fetching the files that i expect.Plus i want to restrict my search to .sh files only.

Yes. Consider main part of the command:

find /

You can try and run it. Slash is pointing to the location you would like to start your search from so no matter where you are it will always start searching from the root directory.

i want to restrict my search to .sh files only.
How can i do that?

just add the condition:

find / -iname "*.sh"

there is difference between -name and -iname switch. As we were talking before, iname is case insensitive.

You mean this?

find / -iname "*.sh" -exec grep -l -i "word_to_search" '{}' ';'

Please post the full command

AFAIR it should work on Solaris as well

---------- Post updated at 02:49 PM ---------- Previous update was at 02:45 PM ----------

The one you posted should be correct. I do not have solaris here to try but on linux it works. I have copy-pasted that.

Hi
It throws an error

find / -iname "*.sh" -exec grep -l -i "word_to_search" '{}' ';'
find: bad option -iname
find: [-H | -L] path-list predicate-list


I see. Solaris does not have GNU find so try:

find / -name �your-file.name'.... 

instead and finish with -exec blabla ';'

find / -name "*.sh" -exec grep -Hi "word_to_search"  {} \;

Hi Murphy,
My OS is SunOS
When i executed your command i got a message

grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- H
Usage: grep -hblcnsviw pattern file . . .
find: stat() error /usr/share/gnome/javahelp/iiim-properties/pt_BR/JavaHelpSearch: Permission denied
find: stat() error /usr/share/gnome/javahelp/iiim-properties/pt_BR/figures: Permission denied
find: stat() error /usr/share/gnome/javahelp/iiim-properties/pt_BR/apply-to-all-lang.html: Permission denied
find: stat() error /usr/share/gnome/javahelp/iiim-properties/pt_BR/ar01s02s01.html: Permission denied
find: stat() error /usr/share/gnome/javahelp/iiim-properties/pt_BR/ar01s02s02.html: Permission denied



your grep does not know option -H so use -l. Stat error is given because of the incorect user permissions.

1 Like

Smoofy thanks .So tell me what command i can use:rolleyes:

Try:
find / -name `*.sh` -exec grep -li "word_to_search" '{}' ';'