Solved

Filtering a list for the IP

Posted on 2004-08-08
9
241 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 100 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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 50 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 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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‚Ķ
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

772 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