Solved

Filtering a list for the IP

Posted on 2004-08-08
9
240 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now