How to find a string inside files | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to find a string inside files

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-07-2007
yoavbe yoavbe is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 9 April 2013, 8:13 AM EDT
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
How to find a string inside files

Hi,
I would like to know how to get a list of files that contain a specific string inside them.
Thanks
Sponsored Links
    #2  
Old 04-07-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 29 July 2011, 5:17 AM EDT
Location: Bangalore
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by yoavbe
Hi,
I would like to know how to get a list of files that contain a specific string inside them.
Thanks
if u know what is the string u r looking for,just mention it in ur ls command..

ls *ur string*
Sponsored Links
    #3  
Old 04-07-2007
ripat ripat is offline Forum Advisor  
Registered User
 
Join Date: Oct 2006
Last Activity: 17 February 2014, 7:51 AM EST
Location: Belgium
Posts: 537
Thanks: 4
Thanked 38 Times in 28 Posts
I think that the OP wants to list the files (not file name) that contains a string.
That's a job for grep.


Code:
# grep 'string' /path/to/files/*

    #4  
Old 04-07-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 16 Times in 16 Posts
all these tools can find 'strings' in your files
sed, awk, grep
Sponsored Links
    #5  
Old 04-07-2007
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 6 February 2014, 3:51 AM EST
Location: Austria/Vienna
Posts: 675
Thanks: 21
Thanked 31 Times in 30 Posts
for recursive search do
grep -R yourstring /path/to/dir
if grep -R is not available, use
find /path/to/dir -type f -print -exec grep yourstring {} \;
Sponsored Links
    #6  
Old 04-08-2007
reborg's Avatar
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 10 Times in 10 Posts
Quote:
Originally Posted by funksen
for recursive search do
grep -R yourstring /path/to/dir
if grep -R is not available, use
find /path/to/dir -type f -print -exec grep yourstring {} \;

Code:
find /path/to/dir -type f -print -exec grep -l  yourstring {} /dev/null \;

Sponsored Links
    #7  
Old 04-08-2007
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 6 February 2014, 3:51 AM EST
Location: Austria/Vienna
Posts: 675
Thanks: 21
Thanked 31 Times in 30 Posts
Quote:
Originally Posted by reborg
Code:
find /path/to/dir -type f -print -exec grep -l  yourstring {} /dev/null \;

find /path/to/dir -type f -exec grep -l yourstring {} \;


if you use grep -l you must use find without -print
whats the /dev/null for? do you mean 2>/dev/null??
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding files with a certain name string inside of another file. tes218 UNIX for Dummies Questions & Answers 4 02-15-2012 08:38 AM
Searching for a string in .PDF files inside .RAR & .ZIP archives. lewk Shell Programming and Scripting 3 03-28-2011 03:06 AM
How to find a file with specific string inside it. pinga123 UNIX for Dummies Questions & Answers 3 05-07-2010 06:50 AM
How to find files only inside the subdirectories only? Tuxidow Shell Programming and Scripting 3 09-08-2009 07:09 AM
String substitution on find results inside exec/xargs myndcraft Shell Programming and Scripting 2 05-17-2008 02:36 PM



All times are GMT -4. The time now is 09:33 AM.