[Solved] Finding a word in all shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Finding a word in all shell scripts
# 8  
Old 08-19-2013
Quote:
Originally Posted by smoofy
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.

Last edited by rafa_fed2; 08-19-2013 at 10:39 AM..
# 9  
Old 08-19-2013
Yes. Consider main part of the command:
Code:
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.
# 10  
Old 08-19-2013
Quote:
Originally Posted by smoofy
Yes. Consider main part of the command:
Code:
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?
# 11  
Old 08-19-2013
just add the condition:
Code:
find / -iname "*.sh"

there is difference between -name and -iname switch. As we were talking before, iname is case insensitive.
# 12  
Old 08-19-2013
Quote:
Originally Posted by smoofy
just add the condition:
Code:
find / -iname "*.sh"

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

You mean this?

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

Please post the full command
# 13  
Old 08-19-2013
AFAIR it should work on Solaris as well

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

Quote:
Please post the full command
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.
# 14  
Old 08-19-2013
Quote:
Originally Posted by smoofy
AFAIR it should work on Solaris as well
Hi
It throws an error


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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to refer more than 9 command line inputs for a scripts in korn shell?

Hi all, I have a script which should take more than 9 command line inputs while running. Likescript.sh a s d f g h j j k l o p i u y t r e w Now in the script if I have to access one of the input which is at position after 9, in this case say 'p' then how can I do that? echo $12 will not work... (15 Replies)
Discussion started by: pat_pramod
15 Replies

2. Shell Programming and Scripting

[Solved] Search for a word and print the next word

Hi, I am trying to search for a word and print the next word. For example: My text is "<TRANSFORMATION TYPE ="Lookup Procedure">" I am searching for "TYPE" and trying to print ="Lookup Procedure" I have written a code like following: echo $line | nawk... (4 Replies)
Discussion started by: sampoorna
4 Replies

3. Shell Programming and Scripting

[Solved] Running scripts in parallel

i have script A and script B, both scripts have to run in parallel, my requirement is script A create table temp1, post creating it will run fr 4 hrs , script B has to start 0nly after creation of table temp1 ( which is done by script A) , again script B will run for 5 hrs if i run sequencially... (7 Replies)
Discussion started by: only4satish
7 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

5. Shell Programming and Scripting

[Solved] Finding the next line when a pattern matches

Hi I have a file like this Record 182: Rejected No Data found Record 196: Rejected File Not Found Record 202: Rejected Invalid argument Record 212: Rejected Bad data My requirement is to search for the value "Record" and if found, then return the next line of it. So,... (3 Replies)
Discussion started by: mr_manii
3 Replies

6. Shell Programming and Scripting

Finding a specific word

Hi, I am trying to develop a script which should find a word if a particular word exists. Below is the content of the file. insert_job: test_job ----> job name days_of_week: all start_times: "16:00" date_conditions: 1 insert_job: test_job2 ----> job name days_of_week: all... (16 Replies)
Discussion started by: rpatty
16 Replies

7. Shell Programming and Scripting

Solved: finding diff in files

i want to compare 2 files and generate below 3 files: 1. new lines 2. updated lines 3. deleted lines are there any one liners for each one of them. Note the method to find duplicates is based on field 1, values are separated by '|' example: test1 (older file) 1|XXX 2|YYY... (3 Replies)
Discussion started by: manishma71
3 Replies

8. Emergency UNIX and Linux Support

Getting last 50 lines after finding a word

Hi All, I have a requirement as below I need find for a string in a log file and once i found that string i need to send a mail.Thsi can be done thru grep and mailx cmnd. Here once i found the string i need to send last 50 lines(up) from where string found. Actually they require to find... (9 Replies)
Discussion started by: pssandeep
9 Replies

9. Shell Programming and Scripting

Finding a word in a file

Hi frndz, i have a flat file like, xxx yyy zzz sss aaa bbb yyy xxx rrr sss ttt yyy ddd zzzz cccc.. look, in this file i want to fetch the substring from one yyy to another one and need to print it then from next values between yyy's.. can you please give me some inputs on this.. ... (10 Replies)
Discussion started by: smr_rashmy
10 Replies

10. UNIX for Dummies Questions & Answers

finding out tables not used in scripts.

Hi all, Please see my requirement and post me asap. Spool all the tables names into a file . Take each table name and check if it is present in any of the scripts in a directory using grep -il command. The script has to loop through the tables list and take each table and find it's presence... (7 Replies)
Discussion started by: Vasundhara
7 Replies
Login or Register to Ask a Question