LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
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
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:19 AM.

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