linux:更短的“主机”命令输出

Sch*_*tod 2 domain-name-system linux host dig

我正在使用 dns 来管理我的虚拟主机。为了做到这一点,我使用 host 命令查询我的名称服务器以获取某些值。例如:

> host -t txt mycl1.vz
mycl1.vz.myserver.de descriptive text "1026"
Run Code Online (Sandbox Code Playgroud)

但我只需要1026作为没有喋喋不休的答案。目前我正在使用 sed 将其删除,例如:

| sed -e 's/.*descriptive text "\(.*\)"/\1/'
Run Code Online (Sandbox Code Playgroud)

但这似乎有点“不稳定”,我想知道是否有一些命令可以首先给我简单的输出?

daw*_*wud 8

dig(1)+short标志一起使用:

$ 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"
Run Code Online (Sandbox Code Playgroud)

如果要删除引号,只需通过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
Run Code Online (Sandbox Code Playgroud)