大网数据广告活动
服务器运维问答

linux: shorter 'host' command output

· 52CE 我爱测

I'm using dns to manage my virtual hosts. In order to do so I query my nameserver with the host command for certain values I need. For example: > host -t txt mycl1.vz mycl1.vz.myserver.de descriptive text "1026" but I only need 1…

问题原文

原帖链接 · Scheintod · CC BY-SA 4.0

I'm using dns to manage my virtual hosts. In order to do so I query my nameserver with the host command for certain values I 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?

已采纳解答

原帖链接 · dawud · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-10-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。