Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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
up vote 8 down vote accepted

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

$ host -t txt descriptive text "v=spf1 ip4: ip4: ~all"

$ dig -t txt +short
"v=spf1 ip4: ip4: ~all"

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

$ dig -t txt +short | sed 's/"//g'
v=spf1 ip4: ip4: ~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

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

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.