Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How to find a string inside files

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 39 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 Unix and Linux 04-07-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
all these tools can find 'strings' in your files
sed, awk, grep
Sponsored Links
    #5  
Old Unix and Linux 04-07-2007
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 30 April 2014, 10:11 AM EDT
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 Unix and Linux 04-08-2007
reborg's Unix or Linux Image
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 11 Times in 11 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 Unix and Linux 04-08-2007
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 30 April 2014, 10:11 AM EDT
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 02:47 AM.