How to search a file within the sub folders?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search a file within the sub folders?
# 1  
Old 11-29-2008
How to search a file within the sub folders?

Hi All,

I'm looking for the UNIX shell script to search a file having some characters within a particular path which intern have many sub folders in it.

Regards
Anil
# 2  
Old 11-30-2008
It's not clear what you are asking. Are you searching for a file name? Or do you want to find which file has some characters in its contents?

If you are searching for a file with certain characters in it's name, the find command is probably what you want.

If you are searching for a file with certain characters in it's contents, the grep command is probably what you want.
# 3  
Old 11-30-2008
Hi KenJackson,
Thanks for the reply.

Let me explain the requirement in detail:

Lets say i'm currently in /apps/appl_top/adm

under this path there are many folders ex : SQL,BIN,REPORTS.Under each folders there are sub folders in which there are files.

Now I want to search a file xxxxx.x having word "yyyy" in the /adm path.

I can use grep to search a particular file in a single directory.But i'm looking for a script or command that can search a file xxxxx.x having word "yyyy" in all the dfolders under /adm path.

Regards
Anil
# 4  
Old 11-30-2008
Then try this. The -H switch tells grep to print the filename. The funny syntax, '{}' \;, is just the way find works.
Code:
find /adm -type f -exec grep -H yyyy '{}' \;

If there aren't too many files for grep to handle on one command line, you can do it this way:
Code:
grep yyyy $(find /adm -type f)

# 5  
Old 11-30-2008
Quote:
Originally Posted by kleanil
Now I want to search a file xxxxx.x having word "yyyy" in the /adm path.
Code:
find /apps/appl_top/adm/ -type f -name "xxxxx.x" -exec grep -iH "yyyy" {} \;

# 6  
Old 11-30-2008
Save some time and energy by using that slightly modified syntax:

Code:
find /adm -type f -exec grep -H yyyy '{}' +

or
Code:
find /apps/appl_top/adm/ -type f -name "xxxxx.x" -exec grep -iH yyyy {} +

# 7  
Old 11-30-2008
Hi All,

Thank you so much.
You guys are too good.

Regards
Anil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop through the folders and search for particular string in files

Hello, Opearting System Environment : HP Unix B.11.31 U I look for script to On specific folders list On specific filelist Search for given string For Example : r48_buildlib.txt contains wpr480.0_20161027 wpr480.0_20161114 wpr481.0_20161208 wpr482.0_20161222... (4 Replies)
Discussion started by: Siva SQL
4 Replies

2. Shell Programming and Scripting

Search for specific file type in subdirectory with multiple folders

I have a directory that is in the below order (the --- is not part of the directory tree, only there to help illustrate: DATE --- main level Folder1 --- level under DATE plugin_out --- level under Folder1 variantCaller_out.40 --- level under plugin_out 001,002,003 --- level under... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

search data from text file in different folders

I am fairly new to unix scripting, the problem is i can understand the unix script. but i fail to write. I do not know where to start and how to end. I am sure this forum will help to achive my dream scriptings in unix. Thanks in adv for your help. Here I need.. I have list of columns in one... (2 Replies)
Discussion started by: dsnrhdy
2 Replies

4. Shell Programming and Scripting

Script to search specific folders dates /mm/dd/ structure

Hi, I have a script that handles a huge amount of log files from many machines and copies it into a SAN location with the following directory structure: /SAN/machinenames/yyyy/m/d so for example /SAN/hosta/2011/3/12/files* Now I am writing a bash script to search for files between to date... (4 Replies)
Discussion started by: GermanJulian
4 Replies

5. Shell Programming and Scripting

Search and Replace text in folders and Subfolders

Hi, I need help in writing a script to search a particular text in multiple files present in folders and sub folders and replace it with another string which also has special characters like '&', '|', etc.. I know sed command will be used to replace the text but i'm not sure how to use it for... (5 Replies)
Discussion started by: Asheesh
5 Replies

6. Shell Programming and Scripting

Search files from sub folders

A folder contains 30-50 subfolders generated on a daily basis, each subfolder contains more than 10-20 files of .html.gz files format. we have to manually convert the .html.gz file to .html format on a daily basis available in all the sub folders. the procedure we are following is copying... (3 Replies)
Discussion started by: Nareshp
3 Replies

7. Shell Programming and Scripting

How to exclude folders/files in search?

I have a directory with about 20 folders and many different types of files. I need to search for files and gzip in all the directories except for 1 directory. How do you exclude a directory? (2 Replies)
Discussion started by: bbbngowc
2 Replies

8. UNIX for Dummies Questions & Answers

How do I search while skipping folders?

I have a directory that contains some specific files. I want to find all the files and copy them to a different directory, however the files are in /dir1/dir2/dir3/filedir/archive. In ~/filedir contains about 100 directories that contains an archive directory where the files I need are. How can I... (6 Replies)
Discussion started by: bbbngowc
6 Replies

9. Shell Programming and Scripting

To search for folders alone?

hi Guys, Here i am again,, I need to search for folders alone present in the system,, I tried this command,, find / -name "name of folder" -print But am getting the name of the files also.. i want only the folders name Thanks guys,,, I know i have to repeat the last statement... (3 Replies)
Discussion started by: mac4rfree
3 Replies

10. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies
Login or Register to Ask a Question