免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 714 | 回复: 1

[文本处理] 如何抽取目标行下面的一段 [复制链接]

论坛徽章:
0
发表于 2017-03-03 22:00 |显示全部楼层
man hostname 将输出信息,包含下面一段

   THE FQDN
       The  FQDN  (Fully Qualified Domain Name) of the system is the name that
       the resolver(3) returns for the host name, such as, ursula.example.com.
       It  is  usually  the hostname followed by the DNS domain name (the part
       after the first dot).  You can check the FQDN using hostname --fqdn  or
       the domain name using dnsdomainname.

       You cannot change the FQDN with hostname or dnsdomainname.

       The  recommended  method of setting the FQDN is to make the hostname be
       an alias for the fully qualified name using /etc/hosts,  DNS,  or  NIS.
       For  example,  if  the  hostname was "ursula", one might have a line in
       /etc/hosts which reads

              127.0.1.1    ursula.example.com ursula

       Technically: The FQDN is the name getaddrinfo(3) returns for  the  host
       name returned by gethostname(2).  The DNS domain name is the part after
       the first dot.

       Therefore it depends on the configuration of the resolver  (usually  in
       /etc/host.conf) how you can change it. Usually the hosts file is parsed
       before DNS or NIS,  so  it  is  most  common  to  change  the  FQDN  in
       /etc/hosts.

       If  a machine has multiple network interfaces/addresses or is used in a
       mobile environment, then it may either have multiple FQDNs/domain names
       or  none  at  all.  Therefore  avoid  using  hostname  --fqdn, hostname
       --domain and dnsdomainname.  hostname --ip-address is  subject  to  the
       same limitations so it should be avoided as well.

如何抽取出这一段?

man hostname |grep  'THE FQDN'

没有办法的话,抽取出  THE FQDN 这一行到结尾的全部信息?

论坛徽章:
54
2015亚冠之德黑兰石油
日期:2015-07-07 13:00:1615-16赛季CBA联赛之深圳
日期:2016-03-31 09:03:5415-16赛季CBA联赛之辽宁
日期:2016-05-09 20:38:15程序设计版块每日发帖之星
日期:2016-05-12 06:20:0015-16赛季CBA联赛之四川
日期:2016-05-13 15:19:4715-16赛季CBA联赛之福建
日期:2016-05-15 20:24:34每日论坛发贴之星
日期:2016-05-16 06:20:0015-16赛季CBA联赛之吉林
日期:2016-05-26 11:49:4715-16赛季CBA联赛之广东
日期:2016-05-26 13:49:18极客徽章
日期:2016-12-07 14:05:2315-16赛季CBA联赛之广夏
日期:2016-12-20 17:33:532017金鸡报晓
日期:2017-01-10 15:19:56
发表于 2017-03-03 22:15 |显示全部楼层
  1. awk '/^OPTION/{exit}/^ +THE FQDN/{f=1}f'
复制代码

  1. sed -rn '/^OPTION/q;/^ +THE FQDN/,$p'
复制代码

评分

参与人数 1信誉积分 +5 收起 理由
yufeiluo + 5

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP