LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   trying to use find and grep, but don't know well enough. (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-use-find-and-grep-but-dont-know-well-enough-51228/)

duhduhdude 03-22-2003 06:30 PM

trying to use find and grep, but don't know well enough.
 
hi

i am trying to use find and grep to find out all occurrences of a particular ip address in any of my files.

i am using find * /| grep xx.xxx.xx.xx

and i cannot get any files. can somebody ehlp me with the right syntax ?

Palin 03-22-2003 06:44 PM

well the usage for grep is

grep <switches> <pattern> <file list>

to find a string in a set of files I use
grep -H <pattern> <file list>

I think you use find where <file list> is not really sure though
you should check the man page for the rest of the switches for grep.

cuckoopint 03-22-2003 07:21 PM

Quote:

I think you use find where <file list> is not really sure though
do you mean grep's -r (recursive) option?

duhduhdude 03-22-2003 07:48 PM

this one doesn't seem to work
 
i tried using grep with -H as well as -r option. doesn't seem to work.

cuckoopint 03-22-2003 08:03 PM

well, what do you get, vs. what do you want to get?

Code:

grep -r xx.xxx.xx.xx /

duhduhdude 03-22-2003 08:15 PM

i am not getting nothing. basically i just want to find all files that contain an occurrence of a particular ip address.

just as in windows, as we search all files and folder, including system and hidden, for text containing duhduhdude, we may get for example file idiots.txt which contains a text saying "the first idiot is duhduhdude, we are yet to find more"

so that i can go to idiots.txt and edit it.

cuckoopint 03-22-2003 08:21 PM

Quote:

i am not getting nothing.
Either:
1. you're syntax is wrong. double check your syntax
2. you don't have permissions for the files
3. no file exists with the ips.

One way to check this would be to search for something obvious, like:
grep -r a /

which would search for 'a' in all files. after you get some results to show the command actually works, press ctrl-c to stop it.

If this worked, but the previous did not, no files exist with your ip. maybe create a temp file with the ip, and search again. This time, you should atleast get this one result.

duhduhdude 03-22-2003 08:28 PM

i created a file duh.txt on the root folder with that particular ip "xxx.xx.xx.xx"

grep -r xxx.xx.xx.xx / did not yield me any result :( did not even show me that file.

cuckoopint 03-22-2003 08:39 PM

ok, let's try one last thing.
create a file with the ip address in your home dir.
then, do:
grep -r "xxx.xx.xx.xx" ~/*

if this works, it may be that it was b/c of permission problems or the use of quotes in the expression.

if not, maybe you're grep is messed up. :(

duhduhdude 03-22-2003 08:44 PM

thanks so much, that worked.


All times are GMT -5. The time now is 08:18 AM.