Solved

Filtering a list for the IP

Posted on 2004-08-08
9
239 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
Comment Utility
Hi MAVERICK,

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

Sunnycoder
0
 
LVL 38

Accepted Solution

by:
yuzh earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
agreed, greenly assumed that the questioner replaces the/my grep pattern by a more generic one ;-)
0
 
LVL 1

Author Comment

by:MAVERICK
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

762 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

15 Experts available now in Live!

Get 1:1 Help Now