LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2010, 08:39 AM   #1
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Rep: Reputation: 16
Question the IP on the second address


Hi all,

got stuck on the followings and need your help, please.

when i do nslookup by name (loop2) i get the followings:

Code:
#nslookup loop2

server: mainsrv-local.local
address: 192.168.0.1

server: loop2-local.local
address: 192.168.20.36
i am interested in the second address (address: 192.168.20.36) have output only the ip address. so to get only 192.168.20.36.
tried different ways with sed and awk but so far nothing worked any suggestions? getting the ip from the second address makes it difficult.

thank you in advance.
 
Old 09-24-2010, 08:43 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

One way of doing this:

nslookup loop2 | sed -n '$s/address: //p'

Hope this helps.
 
Old 09-24-2010, 08:44 AM   #3
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Code:
nslookup ... | ruby -ane 's=$F[-1].chomp if /address/;END{puts s}'
 
Old 09-24-2010, 08:47 AM   #4
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Hi,

Maybe using the host command might be easier for you. I think nslookup has been replaced by host or dig for a while now.
 
Old 09-24-2010, 09:06 AM   #5
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
thanks for the replies.

i used:

Quote:
nslookup loop2 | tail -4 | grep -ir "Address" | awk -F ":" '{print $2}'
it works fine but do not like using the tail -4 as it could change, any better idea?

also, tried :

Quote:
nslookup loop2 | sed -n '$s/address: //p'
but no go...!!

Thanks
 
Old 09-24-2010, 09:19 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Always with you wanting to be complicated ... lol
Code:
nslookup loop2 | sed -n '/loop2/{n;s/address: //p}'

nslookup loop2 | awk -F"[ \t]*:[ \t]*" '/loop2/{getline;print $2;exit}'

nslookup loop2 | awk '/loop2/{getline;gsub(/^.* /,"");print;exit}'
 
1 members found this post helpful.
Old 09-24-2010, 12:09 PM   #7
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
AS always Thanks grail.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to assign globa lIPv6 address and bind() to the previously assigned address. mwnn Linux - Networking 2 10-07-2010 02:29 AM
Address Space Randomization on 2.6.28-15-generic ubuntu 9.04. Finding base address nullprocess Linux - Kernel 0 09-14-2009 10:45 AM
Router gateway address being picked up as primary DNS address under SuSe Hubmasterflex Linux - Networking 13 10-18-2008 01:40 PM
Single DHCP server ,to provide the ip address to a MAC address in two different subne alix123 Linux - Software 5 05-08-2007 11:16 PM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration