Grep for all ip addresses mentioned in all files in a Directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep for all ip addresses mentioned in all files in a Directory
# 1  
Old 11-24-2016
RedHat Grep for all ip addresses mentioned in all files in a Directory

I wish to traverse all files and folders under a given directory say "/tmp/configuration" and
Quote:
grep / search
for all ip address mentioned therein.

I tried find ./ -type f | xargs grep "*.*.*.*" but it does not populated the correct results.

Can you please suggest.
# 2  
Old 11-24-2016
Try something like:
Code:
find . -type f -exec grep -E -- '([0-9]{1,3}\.){3}[0-9]{1,3}' {} +

You need a backslash before literal dots, since dots has a meaning in regular expression, namely "any character" and you need a character before the asterisks, since they are regular expressions, not unix patterns.

Last edited by Scrutinizer; 11-24-2016 at 09:29 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sifting out mail addresses with grep and regex

Hi there from a newbie. So, I have this huuuge portion of mail addresses with names interlaced.. looks like: "name1" <mail1@domain1.com>, "name2" <mail2@domain2.com> ... Sometimes there are no names, just mailaddress. My thought was to use regex with grep. I saved the list in file ma and... (2 Replies)
Discussion started by: dr_xemacs
2 Replies

2. UNIX for Beginners Questions & Answers

Can I combine below mentioned grep commands using OR (when searching strings having spaces)

Command 1: $script | grep 'Write to ECC( SSID=MARGIN)' Command 2: $script | grep 'is not greater than existing logical processing' The above commands run my script and search the mentioned strings but I do not want to run my script twice. It is increasing run time. Can someone tell me... (3 Replies)
Discussion started by: Tanu
3 Replies

3. Homework & Coursework Questions

Search email addresses using grep command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Let's say if we have a file with a lot of information. For example: iiadam otterhedgehog kayleigh... (2 Replies)
Discussion started by: ForeignGuy
2 Replies

4. Shell Programming and Scripting

Grep for string, but within mentioned bounds

Hi, I've been trying to filter a file which has several repetitions of lines which looks as follows: ('hello My name is jamie blabla xyz>>) Each line has different values in them. I want grep or awk or sed to treat everything within the (' and >>) as one line and then filter for a... (2 Replies)
Discussion started by: jamie_123
2 Replies

5. Shell Programming and Scripting

Grep showing all files name of the directory

Hi All, Can any one help me here.I'm getting whole files name of the directory along with the grep result. below is the code var=`grep -i '127.3.3.1' _record` echo $var (9 Replies)
Discussion started by: netdbaind
9 Replies

6. Shell Programming and Scripting

How to replace all ip addresses in all files in directory in ksh?

Hi All, I have a directory containing a lot of files and I want to search all files which contains IP addresses pattern and want to replace those ip addresses with equal number of, say, some character, 'x'. So after replacement the file should not contain any IP address. Like 10.122.53.5 ->... (3 Replies)
Discussion started by: sanzee007
3 Replies

7. Shell Programming and Scripting

How to grep all the files inside the directory and Sub directory

Hi, I have used the command cat * | grep -r <<String>> * It returns: cat : JAN : is directory *********************** ********************* My directory structure: log - JAN -catalina.out -FEB -catalina.out -MARCH ... (11 Replies)
Discussion started by: nanthagopal
11 Replies

8. Shell Programming and Scripting

Formatting list of IP addresses into a grep command

Hi I have an input file with a list of random IP addresses, each on a new line. Below is just an example as I omitted the real IP addresses for obvious reasons. Input: random_ip.txt 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

Finding the executable files of a directory using Grep

Hi guys, Can you please help me print all the executable files of a directory(in this case /home) using grep? All i know is that this command should do it but it doesnt... ls -l ~ | grep -..x it shows me the following mesage grep: invalid option -- '.' Χρήση: grep ... ΥΠΟΔΕΙΓΜΑ ... (3 Replies)
Discussion started by: jimas13
3 Replies

10. Shell Programming and Scripting

grep all files in a directory

I am not sure if i am doing this correctly since it returns quickly. i need to grep for a keyword in all files in a directory grep keyword /mydirectory is that correct? I just want to know which files have a keyword in it. i am using korn shell in solaris 5.1. There does not appear to... (12 Replies)
Discussion started by: guessingo
12 Replies
Login or Register to Ask a Question