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-4175500290/)

RMS# 04-02-2014 05:27 AM

Linux command to find all files in a directory which contain ip addresses
 
i read about general ip address finding but i want to find ip address 192.168.x.x in all files which contains.Thanks your answers

Linux command to find all files in a directory which contain ip addresses like 192.168.x.x

Drakeo 04-02-2014 05:34 AM

http://en.wikipedia.org/wiki/Grep

Madhu Desai 04-02-2014 05:53 AM

1. Lazy way:
Code:

$ grep '192.168.' /directory/*
2. Specific way:
Code:

$ export IP4a='192.168.\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){1}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'
$ grep -E "$IP4a" /directory/*

3. Perfect way (any ip, but only ip4):
Code:

$ export IP4='\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'
$ grep -E "$IP4" /directory/*


RMS# 04-02-2014 06:57 AM

thanks your answers but i take error :

/directory/* : no such file or directory

grail 04-02-2014 09:17 AM

Quote:

/directory/* : no such file or directory
This was to be an example which you would need to replace with the directory YOU want to use.


All times are GMT -5. The time now is 05:30 PM.