Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In a script I want to be able to write an IP address to somewhere easily, so I thought using dig (or a similar command) with back-ticks.

However the simplest output I've been able to come up to wrt dig parameters is

> dig -t A +noall +answer www.google.com
www.google.com.     300 IN  A
www.google.com.     300 IN  A

Any way (extra arg, different tool instead of dig?) to get rid of the junk apart from the IP address?? (And please don't tell me to use sed.)


share|improve this question

2 Answers 2

up vote 7 down vote accepted

On the CentOS box I have to hand

dig +short   www.google.com

If you only want one address then

dig +short   www.google.com | head -1


dig +short   www.google.com | tail -1
share|improve this answer

sed is a viable option and outright rejecting it is misguided at best.

Anyway, try

dig -t A +noall +answer www.google.com | cut -f 6 | tail -1
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.