Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Filtering a list for the IP

Posted on 2004-08-08
9
Medium Priority
?
250 Views
Last Modified: 2010-04-21
I have the grep output;
#grep -nr '10.0.0.84' *
zones9/25/mydomain.tld:11:*   86400 IN A 10.0.0.84  ;Cl=2

I want the IP from that line - using a shell script.

Thanks alot
0
Comment
Question by:MAVERICK
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11750297
Hi MAVERICK,

grep x.x.x.x | sed 's/.* IN A \([^\.]*\.[^\.]*\.[^\.]*\.[^ ]*\).*/\1/'

Sunnycoder
0
 
LVL 38

Accepted Solution

by:
yuzh earned 400 total points
ID: 11750310
Here's an example script

#!/bin/ksh
LINE="zones9/25/mydomain.tld:11:*   86400 IN A 10.0.0.84  ;Cl=2"
IP=`echo $LINE | awk '{print $5}' `
echo " the IP is $IP "
exit



0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11754012
hmm, yuzh's suggestion misses the matching part, I'd use:

awk '($5=="10.0.0.84"){print $5;exit;}' *

# feel free to improve in many ways ;-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:MAVERICK
ID: 11754872
Sunnycoder: I was unable to get your suggestion to run
yuzh: your suggestion solved the immediate question
ahoffmann: I'm not particularly familiar with awk, but i'd love be :) This was a small part of a larger question

There is a follow-on question posted here;
http://www.experts-exchange.com/Operating_Systems/Unix/Q_21087259.html

Thanks
Maverick
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11757518
You don't need the -n flag on grep as you're not using the output from it.

grep -r '10.0.0.84' | awk '{print $5}'

If you don't need to recurse, you use ahoffmann's suggestion.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 200 total points
ID: 11757519
You don't need the -n flag on grep as you're not using the output from it.

grep -r '10.0.0.84' * | awk '{print $5}'

If you don't need to recurse, you use ahoffmann's suggestion.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11758807
"hmm, yuzh's suggestion misses the matching part, I'd use:"

I didn't forget!, I just can't see the point to use something like:
   
grep -r '10.0.0.84' * | awk '{print $5}'

reresult would be 10.0.0.84 or nothing.

you can use:

if `grep '10.0.0.84' *` ; then
    IP="10.0.0.84"
else
    echo "No such IP!"
fi
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 200 total points
ID: 11760478
agreed, greenly assumed that the questioner replaces the/my grep pattern by a more generic one ;-)
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 11765933
Even though matching was not really required (I was processing a list) Thanks everyone for the tips on shell scripting - something i need to learn more on ;-)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question