LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2011, 09:02 AM   #1
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Rep: Reputation: 15
question about finding string in multiples files


Guys...

when I want to search for a string on multiples files I cd to the directory where the files are... then I do this:

for i in Žls -AŽ; do grep <STRING VALUE> $i; done


what if I want to look for values on all folder and sub folders?



thanks
 
Old 04-18-2011, 09:09 AM   #2
rhamel
Member
 
Registered: Sep 2009
Location: Caribbean
Distribution: Slackware 15.0, Proxmox 7.4-17, FreeBSD 13.2
Posts: 70

Rep: Reputation: Disabled
Finding strings in files

try

cd /path-to-directory

find . -type f -exec grep -H "search-string-text" {} \;

This will recursively search all files below the current directory and return the match plus the file in which it was found. Saved my bacon more than once.

Cheers.
 
Old 04-18-2011, 09:13 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
You can also use 'grep -r' for recursive grep.
 
Old 04-18-2011, 09:16 AM   #4
Jeroen_
LQ Newbie
 
Registered: Aug 2009
Distribution: debian linux
Posts: 3

Rep: Reputation: 0
Instead of
Code:
for i in `ls -A`; do grep <STRING VALUE> $i; done
you can use
Code:
grep <STRING VALUE> *
And when you want to descend the directory structure use
Code:
grep -r <STRING VALUE> *
From the manpage:
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
 
Old 04-18-2011, 10:09 AM   #5
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Original Poster
Rep: Reputation: 15
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] finding a string in file himu3118 Programming 2 05-10-2010 09:00 AM
Simple bash scripting question, involving finding newer files salasi Linux - Software 2 08-01-2009 03:22 PM
finding a string jkeertir Linux - Newbie 3 03-28-2008 04:45 PM
encode multiples files with lame kevinlux Linux - Software 4 09-19-2004 11:53 AM
Finding files question... tarballed Linux - General 1 03-05-2003 01:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration