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

I'm using dns to manage my virtual hosts. In order to do so I query my nameserver with the host command for for certain values is need. For example:

> host -t txt mycl1.vz
mycl1.vz.myserver.de descriptive text "1026"

but I only need 1026 as answer without the chatter. Currently I'm using sed to remove it like:

| sed -e 's/.*descriptive text "\(.*\)"/\1/'

but this seems a little "unstable" and I wonder if there isn't some command which would give me the plain output in the first place?

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

Use dig(1) with the +short flag instead:

$ host -t txt google.com
google.com descriptive text "v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"

$ dig -t txt google.com +short
"v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"

If you want to remove the quotes, just filter the output through sed:

$ dig -t txt google.com +short | sed 's/"//g'
v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all
share|improve this answer
    
That's what I was looking for. Now I have still to remove the quotes. –  Scheintod Oct 10 '13 at 10:37
add comment

My first choice would be dig as dawud pointed out. If you stick with 'host', you could replace sed with:

cut -d \" -f 2
share|improve this answer
    
Thanks. Good shortcut. But I need it for A records, too. –  Scheintod Oct 10 '13 at 10:38
    
Host has a variable format output. One more reason to use dig for such operations :) (For example cut -d " " -f 4 for A records and host) –  Bgs Oct 10 '13 at 11:19
add comment

Your Answer

 
discard

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.