LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to use grep to search for a specific variable.. (https://www.linuxquestions.org/questions/linux-software-2/how-to-use-grep-to-search-for-a-specific-variable-532083/)

memo007 02-24-2007 05:26 PM

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 . :D

Quakeboy02 02-24-2007 05:30 PM

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

colucix 02-24-2007 05:33 PM

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!

memo007 02-24-2007 05:41 PM

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!


PuppetZ 02-24-2007 05:52 PM

Do you mean:

> grep something *

??


All times are GMT -5. The time now is 06:37 PM.