Formatting list of IP addresses into a grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting list of IP addresses into a grep command
# 1  
Old 02-08-2012
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

Code:
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
10.0.0.1
10.0.0.1

Basically what I would like to do is to take all the IP addresses in the input file and pipe them into an output file eg. zgrep_ip.sh which in essence is a formatted zgrep command from the input file.

Output: zgrep_ip.sh
Code:
zgrep --no-filename -e 10.0.0.1 -e 10.0.0.1  -e 10.0.0.1  -e 10.0.0.1  -e 10.0.0.1  -e 10.0.0.1  *.gz > zgrep.out

I hope it makes sense Smilie
# 2  
Old 02-08-2012
Code:
#! /bin/bash
echo -e 'zgrep --no-filename \c' >> zgrep_ip.sh
while read x; do echo -e "-e $x \c" >> zgrep_ip.sh; done < random_ip.txt
echo -e '*.gz > zgrep.out\c'>> zgrep_ip.sh


Last edited by balajesuri; 02-09-2012 at 03:07 AM..
# 3  
Old 02-08-2012
Quote:
Originally Posted by balajesuri
Code:
#! /bin/bash
echo -e 'zgrep --no-filename \c' >> zgrep_ip.sh
while read x; do echo -e "-e $x \c" >> zgrep_ip.sh; done < random_ip.txt
echo -e '*.gz > zgrep.out\c'>> zgrep_ip.sh


Thanks for your reply, I get the following error;

: No such file or directoryne 3: random_ip.txt
# 4  
Old 02-08-2012
I hope you're not being deliberate here.
What's the name of your input file? The file containing the list of IP's.. Isn't it random_ip.txt ?
# 5  
Old 02-08-2012
Quote:
Originally Posted by balajesuri
I hope you're not being deliberate here.
What's the name of your input file? The file containing the list of IP's.. Isn't it random_ip.txt ?
Correct, the file containing the list of IP's is called random_ip.txt, not sure why your script is not picking it up? I executed your script from within the directory where the random_ip.txt file reside.
# 6  
Old 02-08-2012
Hmmm... It works for me. Not sure why it doesn't work for you.
May be, some random control characters have crept in either your script file or input file.
# 7  
Old 02-08-2012
Why don't you use
Code:
zgrep -F -f random_ip.txt *.gz

Doesn't that work?
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. Shell Programming and Scripting

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 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. (1 Reply)
Discussion started by: mohtashims
1 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. UNIX for Dummies Questions & Answers

Getting parameter list is too long in grep command

Hi i am getting below message while using grep command "The parameter list is too long" grep -i 919716499889 * ksh: /usr/bin/grep: 0403-027 The parameter list is too long. please let me know what changes i can do in this command (5 Replies)
Discussion started by: scriptor
5 Replies

5. UNIX for Dummies Questions & Answers

List Contacted Web Addresses?

Greetings. I'm in the process of tracking down an issue with Firefox, and need some way of gathering the actual web addresses which are connected to from localhost. The specific problem centers around the determination/capture of the exact generated app.update.url address formed by the... (2 Replies)
Discussion started by: LinQ
2 Replies

6. Shell Programming and Scripting

Extract list of IP addresses from a text file.

I have an xml file with IP addresses all over the show. I want to print only the IP addresses and cut off any text before or after the IP address. Example: Note: The IP addresses (x.x.x.x) do not consistently appear in the xml file as per the pattern below. Sometimes there are text before... (8 Replies)
Discussion started by: lewk
8 Replies

7. UNIX for Dummies Questions & Answers

analyzing list with street addresses

Hi List, Could someone please point me into the right direction with the following: I have a file containing a list of street addresses. I need to sort all the street addresses with the same number to a new file containing the street name and corresponding number. So: Strawinskylaan... (3 Replies)
Discussion started by: M474746
3 Replies

8. Solaris

Command to list all the VIP addresses assigned to Solaris server

Hello All, I want to list all the VIP addresses assigned to Solaris server. whats the command we have use on solaris for this? Please help Thanks!! Weblogic Consultant (1 Reply)
Discussion started by: weblogicsupport
1 Replies

9. UNIX Desktop Questions & Answers

Using Mailx to send to list of email addresses

Im trying to use a shell script to send to a list of email addresses in a txt file. Here is what i have tried but it keeps sending to dead.letter... Success.ksh contains... mailx -s"Night Batch Success" 'cat /Scripts/email_addresses.txt' < /Scripts/email_body_message.txt The email body... (1 Reply)
Discussion started by: aguad3
1 Replies

10. UNIX for Dummies Questions & Answers

Help extracting MAC addresses from List

Hello all. I have a large number of text files outputted from various Netstumbler Wireless Scans; from which I need to extract the MAC addresses of the various Access Points. The Text files look like this: # $Creator: Network Stumbler Version 0.4.0 # $Format: wi-scan summary with... (9 Replies)
Discussion started by: dhs23
9 Replies
Login or Register to Ask a Question