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
comparing the content of two directories xyzt UNIX for Dummies Questions & Answers 2 04-29-2008 10:36 AM
searching files through all subdirectories beneath the current directory milagros Shell Programming and Scripting 5 05-15-2007 04:00 PM
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 06:44 AM
Searching for files over 30 days old in current directory cxredd4 Shell Programming and Scripting 18 06-11-2006 02:16 AM
Searching and Removing File Content rkumar28 Shell Programming and Scripting 7 02-27-2005 05:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-23-2008
tiger99 tiger99 is offline
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
  #2 (permalink)  
Old 01-23-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 741
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
  #3 (permalink)  
Old 01-23-2008
tiger99 tiger99 is offline
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
  #4 (permalink)  
Old 01-23-2008
mehmet_demirez mehmet_demirez is offline
Registered User
  
 

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

find . | xargs grep -l "test"
  #5 (permalink)  
Old 01-23-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
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.
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 06:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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