Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filtering a list for the IP

Posted on 2004-08-08
9
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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.

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 …
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…
Suggested Courses

715 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