LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-24-2007, 05:26 PM   #1
memo007
Member
 
Registered: Feb 2005
Distribution: Debian, Kanotix, Kubuntu
Posts: 117

Rep: Reputation: 15
How to use grep to search for a specific variable..


One quick question, how do i use grep to look through all files in a folder for a specific variable .
 
Old 02-24-2007, 05:30 PM   #2
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
This is the way I do it. There are shorter command strings, but I've not bothered to learn them.
Code:
find /xxx -print |xargs grep string
 
Old 02-24-2007, 05:33 PM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
What do you mean for "specific variable"? Grep by itself is not recursive, but you can consider using find to search for some or all the files inside a directory (and eventually its subdirectory) and issue grep on them. A way to do this is
Code:
find . -type f | xargs grep string
where string is any pattern you are looking for. It could be also
Code:
find . -type f | xargs grep $var
if the value of $var is the string you are looking for.

Edit: Quakeboy02 was faster than me in posting the replay Sorry for redundancy!

Last edited by colucix; 02-24-2007 at 05:36 PM.
 
Old 02-24-2007, 05:41 PM   #4
memo007
Member
 
Registered: Feb 2005
Distribution: Debian, Kanotix, Kubuntu
Posts: 117

Original Poster
Rep: Reputation: 15
For instance i have a php or txt file and i want to look inside the script for a specific variable
I've seen it done like this grep -n -p 'whatever' -
But that didnt work so any advice on how to make it work.
Thanks





Quote:
Originally Posted by colucix
What do you mean for "specific variable"? Grep by itself is not recursive, but you can consider using find to search for some or all the files inside a directory (and eventually its subdirectory) and issue grep on them. A way to do this is
Code:
find . -type f | xargs grep string
where string is any pattern you are looking for. It could be also
Code:
find . -type f | xargs grep $var
if the value of $var is the string you are looking for.

Edit: Quakeboy02 was faster than me in posting the replay Sorry for redundancy!
 
Old 02-24-2007, 05:52 PM   #5
PuppetZ
LQ Newbie
 
Registered: May 2005
Location: Barcelona
Distribution: Slackware 11
Posts: 15

Rep: Reputation: 0
Do you mean:

> grep something *

??
 
  


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
grep search... tobiasw Linux - General 4 10-28-2006 01:36 PM
To recursively search with grep grautu Slackware 5 11-21-2005 02:53 AM
can you specify which files to grep search? sneakyimp Linux - Software 4 10-12-2005 08:28 PM
Using Grep to search all sub-directories yrraja Solaris / OpenSolaris 2 08-28-2004 03:29 AM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 09:01 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration