LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux command to find all files in a directory which contain ip addresses. (https://www.linuxquestions.org/questions/linux-newbie-8/linux-command-to-find-all-files-in-a-directory-which-contain-ip-addresses-4175422862/)

Shakthi Yokesh 08-19-2012 03:00 AM

Linux command to find all files in a directory which contain ip addresses.
 
Give a Linux shell command to find all files in a directory which contain ip addresses.

sycamorex 08-19-2012 03:28 AM

Hi and welcome to LQ.

Looks like homework. What have you tried so far?

Shakthi Yokesh 08-19-2012 04:31 AM

@sycamorex: this is not a homework question.It is an interview question.I actually wrote something like
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \; which displays all the IP addressess present in /etc directory.......actually i just want to display the file names in which IP addressess are present....how to do that??please help me

druuna 08-19-2012 04:38 AM

Have a look at grep's -L and -l options.

Shakthi Yokesh 08-19-2012 05:14 AM

@druuna: I could not get your clue.....It would be grateful if u provide me with the command

druuna 08-19-2012 05:16 AM

Did you have a look at the grep man page (man grep)?

Code:

find /etc -exec grep -L '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
find /etc -exec grep -l '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;


Shakthi Yokesh 08-19-2012 05:27 AM

@druuna: Thank u so much for your patience in explaining me this...I got the answer now....Since I am just a beginner in linux it was difficult for me to grasp your clue....once again thank u so much for helping me :)

sycamorex 08-19-2012 05:28 AM

@druuna
I think the OP wants -l not -L


Try:
Code:

find /etc -exec grep -rl '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' {} \;

druuna 08-19-2012 05:31 AM

Quote:

Originally Posted by sycamorex (Post 4758178)
@druuna
I think the OP wants -l not -L

Yep, you are correct!


All times are GMT -5. The time now is 09:32 PM.