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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing the content of two directories xyzt UNIX for Dummies Questions & Answers 2 04-29-2008 07:36 AM
searching files through all subdirectories beneath the current directory milagros Shell Programming and Scripting 5 05-15-2007 01:00 PM
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 03:44 AM
Searching for files over 30 days old in current directory cxredd4 Shell Programming and Scripting 18 06-10-2006 11:16 PM
Searching and Removing File Content rkumar28 Shell Programming and Scripting 7 02-27-2005 02:40 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
searching content of files in the current and sub directories

Hi
I was wondering why command 2 doesn't work like command 1 below.

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

2.
ls -R | grep "test"

I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2?

Thanks in advance for your help
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 570
Quote:
Originally Posted by tiger99 View Post
Hi
I was wondering why command 2 doesn't work like command 1 below.

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

2.
ls -R | grep "test"

I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2?

Thanks in advance for your help
command 2 searches for filenames that have the string "test" as part of their name while command 1 searches for the string "test" inside each of the files.

Code:
ls -R | xargs grep "test"  #this makes command 2 like command 1
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
Hi shamrock
Thanks for your help

However the code you suggested
ls -R | xargs grep "test"

gives me a huge list with ending "No such file or directory".
i.e.
grep: expr.sh: No such file or direcotory

Is it possible to only display the directory and file name when the text that I am searching is found?

Thanks
Reply With Quote
  #4  
Old 01-22-2008
Registered User
 

Join Date: Dec 2007
Location: Istanbul
Posts: 23
try this :

find . | xargs grep -l "test"
Reply With Quote
  #5  
Old 01-23-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
2>/dev/null

Hi,

For the "No such file or directory", it is becuase there are error messages print to the stand output, you can ignore them by adding

Code:
2>/dev/null
at the end of the command,which will stop printing all the error message to stand output which is our screen.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0