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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with GREP. syndex Shell Programming and Scripting 2 07-11-2007 01:44 PM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 08:49 PM
grep problem svennie UNIX for Dummies Questions & Answers 5 11-08-2004 04:29 AM
Grep Problem lesstjm Shell Programming and Scripting 2 10-27-2004 10:13 AM
Grep problem odogbolu98 Shell Programming and Scripting 3 02-18-2003 03:53 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2005
avadhani avadhani is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 15
Grep Problem

Hi,
I want search all files containing some "searchtext" in current dir and sub dir. For this, I used

grep "searchtext" */*

This will search only in sub dir files and does not give results if file containing search text exists in current directory.

and

grep "searchtext" *

This will search only files current directory, not sub directories.

But when I use , following command . I get result.

find . | xargs grep "searchtext"
It searches at both current dir and sub dir .

How to achive this using grep command .

thanks
  #2 (permalink)  
Old 06-22-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by avadhani
But when I use , following command . I get result.

find . | xargs grep "searchtext"
It searches at both current dir and sub dir .

How to achive this using grep command .
Arent you using grep in your command ?

Or do you just want to use grep without the find ?

vino
  #3 (permalink)  
Old 06-22-2005
avadhani avadhani is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 15
Hi,

I want to use only grep command to search keyword in all files (current dir and sub dir)

Thanks
  #4 (permalink)  
Old 06-22-2005
Simerian Simerian is offline
Registered User
  
 

Join Date: Oct 2003
Location: United Kingdom
Posts: 37
find calling command

Quote:
Originally Posted by avadhani
Hi,

I want to use only grep command to search keyword in all files (current dir and sub dir)

Thanks
find has a command option that allows you to run, for instance, a grep against each file it locates. This is sometimes very useful... You'll have to check the man page for the syntax.
  #5 (permalink)  
Old 06-22-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by Simerian
find has a command option that allows you to run, for instance, a grep against each file it locates. This is sometimes very useful... You'll have to check the man page for the syntax.
Here is your answer

Code:
find . -name 'haystack' -exec grep 'needle' {} \; -print
The -print will display the corresponding haystack for each successful needle found.

Vino
  #6 (permalink)  
Old 06-22-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
Quote:
Originally Posted by avadhani
Hi,

I want to use only grep command to search keyword in all files (current dir and sub dir)

Thanks
... i find it quiet interesting that when given the whole gamut of Unix tools that are available to do things with, there are people who insist on only using 1 tool and 1 tool only even when there are other tools that might be able to achive the required results quicker --- unless this is homework ....
  #7 (permalink)  
Old 06-22-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by Just Ice
even when there are other tools that might be able to achive the required results quicker ---

Just Ice,

for learning point of view (atleast for me), how would you approach the OP to suit your statement.

Thanks,
vino
Sponsored Links
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 11:39 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