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
Read text file from a specified string to the end bsrajirs UNIX for Advanced & Expert Users 9 01-11-2008 01:05 AM
String search - Command to find second occurance saurabhsinha23 UNIX for Dummies Questions & Answers 5 12-06-2007 08:03 PM
generate new string from a text file walterwaston Shell Programming and Scripting 6 10-16-2007 03:43 PM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 08:53 AM
How to input username on text file into finger command on shell script Micz Shell Programming and Scripting 3 11-08-2005 02:38 AM

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 11-22-2006
wrwelden wrwelden is offline
Registered User
  
 

Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, USA
Posts: 2
Looking for command(s)/ script to find a text string within a file

I need to search through all files with different file suffixes in a directory structure to locate any files containing a specific string
  #2 (permalink)  
Old 11-22-2006
dhanamurthy dhanamurthy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 105
find . -name '*.*' -exec grep -ilw 'string_name' {} \;

Will this satisfy your requirement ?.
  #3 (permalink)  
Old 11-22-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
I go for,

Code:
find . -name '*.*' -print | xargs grep -il 'pattern'
  #4 (permalink)  
Old 11-22-2006
wrwelden wrwelden is offline
Registered User
  
 

Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, USA
Posts: 2
Thanks to both of you

These examples helped. Thank you.

I do not use shell scripting much. Now I can learn from these results.

The results were :

Code:
devr> find . -name '*.*' -exec grep -ilw 'MAXCOMB' {} \;
./IPY0115.prog
./IPY0130.pl
./condir_and_copy_daily.sh
./IPY0130_old.pl
devr> find . -name '*.*' -exec grep -ilw 'maxcomb' {} \;
./IPY0115.prog
./IPY0130.pl
./condir_and_copy_daily.sh
./IPY0130_old.pl
devr> 
devr> | xargs grep -il 'maxcomb' {} \;                      <
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
./IPY0115.prog
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
./IPY0130.pl
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
./test_file_shell.sh
grep: can't open {}
grep: can't open ;
./dir_copy_daily_files.sh
./dir_copy_biweekly_files.sh
./condir_and_copy_biweekly.sh
./condir_and_copy_daily.sh
grep: can't open {}
grep: can't open ;
grep: can't open {}
grep: can't open ;
./doi_dnld_files.prog
./IPY0130_old.pl
grep: can't open ./View
grep: can't open for
grep: can't open value_set
grep: can't open Role_id.sql
devr> rgs grep -il 'maxcomb'                                <
./IPY0115.prog
./IPY0130.pl
./test_file_shell.sh
./dir_copy_daily_files.sh
./dir_copy_biweekly_files.sh
./condir_and_copy_biweekly.sh
./condir_and_copy_daily.sh
./doi_dnld_files.prog
./IPY0130_old.pl
grep: can't open ./View
grep: can't open for
grep: can't open value_set
grep: can't open Role_id.sql
devr> find . -name '*.*' -print | xargs grep -ilw 'maxcomb'
./IPY0115.prog
./IPY0130.pl
./condir_and_copy_daily.sh
./IPY0130_old.pl
grep: can't open ./View
grep: can't open for
grep: can't open value_set
grep: can't open Role_id.sql
  #5 (permalink)  
Old 11-22-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
you dont have correct permissions to open the file and grep thru it.
  #6 (permalink)  
Old 11-23-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
devr>
devr> | xargs grep -il 'maxcomb' {} \;
xargs and {}
why is that ?

find with xargs grep that would do..

If you dont want to display the output - that files cant be opened
then use 2>/dev/null with find
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 10:28 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