The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 11:08 AM
Recursively copy only specific files from a directory tree sharpsharkrocks Shell Programming and Scripting 3 01-07-2008 02:16 PM
List all files that contain a specific directory Sat510 SUN Solaris 7 04-17-2007 10:57 AM
delete files in specific directory legato Shell Programming and Scripting 2 03-29-2006 09:46 PM
creating object files in a specific directory svh High Level Programming 1 02-13-2006 06:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2008
selamba_warrior selamba_warrior is offline
Registered User
  
 

Join Date: May 2008
Posts: 12
How to find a specific files in a many directory

Dear All,

Appreciate some help here.

I have a log of report. It located in several directory as below:

Directory:
mysscpr1
mysscpr2
mysscpr3
my_scnpr4

In the directory it contain hundred of files.

i need to find a specific files that contain 'invc2345' in the directory.

How can i do that? without need to 'cd <directory name> ' and then use the grep command one by one in every directory such as

cd <directoryname>

grep invc2345 *

Please assist
  #2 (permalink)  
Old 05-28-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
Use the find and grep command together.That should solve the purpose..

Code:
find . -name mysscp l -exec grep invc {} \;
  #3 (permalink)  
Old 05-28-2008
selamba_warrior selamba_warrior is offline
Registered User
  
 

Join Date: May 2008
Posts: 12
Dear nua,

May be my explaination is not clear:

This is the sample of directory:

drwxrwxr-x 3 xxxxx ulol 368640 May 28 14:24 mycrdpr1
drwxrwxr-x 3 xxxxx ulol 96 Oct 19 2007 mycrdpr2
drwxrwxr-x 3 xxxxx ulol 96 Oct 1 2007 mycrdpr3
drwxrwxr-x 3 xxxxx ulol 96 May 23 08:15 myfinpr2
drwxrwxr-x 3 xxxxx ulol 8192 Mar 1 08:26 myfinprn
drwxrwx--- 2 xxxxx ulol 96 Jul 26 2007 mynpprn1
drwxrwxr-x 3 xxxxx ulol 16384 May 26 12:56 mypngpr1
drwxrwxr-x 3 xxxxx ulol 1064960 May 28 14:26 mysscpr2
drwxrwx--- 2 xxxxx ulol 96 May 15 06:00 sgisbprn1

I'm looking for an invoice number JHK8888 where it located in one of the directory and in a file under the directory.

Below is the sample of file under the directory:

-rw-r----- 1 1253 ulol 5386 Jul 6 2007 IBCRNtKL.abor.212113
-rw-r----- 1 1253 ulol 200070 Jul 9 2007 IBCRNtKL.abor.212941
-rw-r----- 1 chaiyeel ulol 5270 Jul 30 2007 IBCRNtKL.chel.2220
50

The problem is i also dunt know where is the file located and under which directory. I dont want to cd directory one by one and user grep to look for the invoice number. I want to make it easy.

Please advice.

Rgrds

Shahril
  #4 (permalink)  
Old 05-28-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 164
grep -R "<Search String>" *
  #5 (permalink)  
Old 05-28-2008
selamba_warrior selamba_warrior is offline
Registered User
  
 

Join Date: May 2008
Posts: 12
Dear siba,

Please find error below:

$ grep -R JHBI11117 *
grep: illegal option -- R
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]
$
  #6 (permalink)  
Old 05-28-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 164
Have u checked the man page for grep command?
If -R is not working then u can use -r here and try it.



Quote:
Originally Posted by selamba_warrior View Post
Dear siba,

Please find error below:

$ grep -R JHBI11117 *
grep: illegal option -- R
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]
$
  #7 (permalink)  
Old 05-28-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Code:

find /path/to/find -type f -name "pattern_of_file" -o -name "pattern_of_file" | xargs grep -i "pattern_to_find"
Thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0