The UNIX and Linux Forums  

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
how to grep the word and display only the second word from it prsam UNIX for Dummies Questions & Answers 11 12-17-2008 01:06 PM
how to grep word from .gz files & .z files udaya_subbu Shell Programming and Scripting 8 08-08-2008 06:53 AM
how to grep for a word and display only the word ananthmm UNIX for Dummies Questions & Answers 6 05-29-2008 09:00 AM
to get the timestamp of files from the files and folders in Unix kishan HP-UX 2 04-09-2008 09:20 AM
removing old files except configuration files and folders jamcalicut Shell Programming and Scripting 1 11-09-2007 04:34 PM

Reply
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 07-16-2009
suresh3566 suresh3566 is offline
Registered User
  
 

Join Date: May 2008
Posts: 26
Arrow how to grep a word from files in different folders

Hi,

I have 10 folders like a1,a2,a3...a10

each folder having 100 files.

how to grep a word from all the files in all folders at a time?
  #2 (permalink)  
Old 07-16-2009
sanjay1979 sanjay1979 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 36
Hi suresh,

try this -

find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

regards
  #3 (permalink)  
Old 07-16-2009
suresh3566 suresh3566 is offline
Registered User
  
 

Join Date: May 2008
Posts: 26
Hi
Its working, but I want the results with file name
  #4 (permalink)  
Old 07-16-2009
pranabrana's Avatar
pranabrana pranabrana is offline
Registered User
  
 

Join Date: Jun 2008
Location: Bangalore
Posts: 21
Quote:
Originally Posted by sanjay1979 View Post
Hi suresh,

try this -

find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

regards


You can try


find . -exec grep "your_word" '{}' \ ; -print

thanks
Pranab
  #5 (permalink)  
Old 07-17-2009
suresh3566 suresh3566 is offline
Registered User
  
 

Join Date: May 2008
Posts: 26
got error


find: 0652-018 An expression term lacks a required parameter.
ksh: -print: not found.

---------- Post updated 07-17-09 at 01:02 AM ---------- Previous update was 07-16-09 at 05:46 PM ----------

Any body plz help me...its a bit urgent

when I tried this command ,,
find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

I am getting the data.but i am unable to find the file/folder name.

key word : 123

required output

folder,file,keyword
a1,file1:123
a5,file4:123
a10,file3:123
  #6 (permalink)  
Old 07-17-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Did you try:

Code:
grep -R "pattern" a*

  #7 (permalink)  
Old 07-17-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
This worked for me :


Code:
find . -type f -name "a*" -print | xargs grep "xyz"  /dev/null

I got it from man pages of "grep"
Reply

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 05:55 AM.


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