免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1772 | 回复: 2
打印 上一主题 下一主题

[文本处理] bind包里面的egrep的用法有问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-07 13:19 |只看该作者 |倒序浏览
在bind-9.3.6-20.P1.el5_8.1的SPEC文件中有一个egrep的用法:

  1. /usr/bin/tail -n '+'`/bin/egrep -n '\\$Id$/+1/' | bc` bin/rndc/rndc.conf | sed '/Sample rndc configuration file./{p;i\
  2. *\
  3. * NOTE: you only need to create this file if it is to\
  4. * differ from the following default contents:
  5. ;d}' > sample/etc/rndc.conf;
复制代码
但是这个语句不能执行完毕,大家来分析看看,为何这个不能执行完毕?

ps,
bin/rndc/rndc.conf的内容如下:

  1. /*
  2. * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 2000, 2001  Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */

  17. /* $Id: rndc.conf,v 1.7.206.1 2004/03/06 10:21:32 marka Exp $ */

  18. /*
  19. * Sample rndc configuration file.
  20. */

  21. options {
  22.         default-server  localhost;
  23.         default-key     "rndckey";
  24. };

  25. server localhost {
  26.         key     "rndckey";
  27. };

  28. include "/etc/rndc.key";
复制代码
这个bind版本的前一个版本是这样的,貌似没有问题:

  1. /usr/bin/tail -n '+'`/bin/egrep -n '\\$Id: rndc.conf,v' bin/rndc/rndc.conf | sed 's/:.*$/+1/' | bc` bin/rndc/rndc.conf | sed '/Sample rndc configuration file./{p;i\
  2. *\
  3. * NOTE: you only need to create this file if it is to\
  4. * differ from the following default contents:
  5. ;d}' > sample/etc/rndc.conf;
复制代码

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
2 [报告]
发表于 2012-11-21 11:40 |只看该作者
原作者好像不太懂awk,或者对编译环境下使用awk 有顾虑。 这个egpre +sed +bc 的命令行可以用一条awk命令替代,就是为了找到$Id: rndc.conf 这行的下一行的行数。
  1. /bin/egrep -n '\$Id: rndc.conf,v' bin/rndc/rndc.conf | sed 's/:.*$/+1/' | bc
复制代码
可以替换为:
  1. awk '/\$Id: rndc.conf,v/{getline;print NR}' bin/rndc/rndc.conf
复制代码
后来更新的代码没有得到任何匹配输出,使得bc 一直在等待,所以无法不能继续执行。

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
3 [报告]
发表于 2012-11-21 11:40 |只看该作者
本帖最后由 rdcwayx 于 2012-11-21 13:43 编辑
wenlujon 发表于 2012-11-07 15:19
在bind-9.3.6-20.P1.el5_8.1的SPEC文件中有一个egrep的用法:但是这个语句不能执行完毕,大家来分析看看,为 ...


原作者好像不太懂awk,或者对编译环境下使用awk 有顾虑。 这个egpre +sed +bc 的命令行可以用一条awk命令替代,就是为了找到$Id: rndc.conf 这行的下一行的行数。
  1. /bin/egrep -n '\$Id: rndc.conf,v' bin/rndc/rndc.conf | sed 's/:.*$/+1/' | bc
复制代码
可以替换为:
  1. awk '/\$Id: rndc.conf,v/{getline;print NR}' bin/rndc/rndc.conf
复制代码
那么tail命令可以替换为
  1. tail -n '+'`awk '/\\$Id: rndc.conf,v/{getline;print NR}' bin/rndc/rndc.conf` bin/rndc/rndc.conf
复制代码
后来更新的代码没有得到任何匹配输出,使得bc 一直在等待,所以无法不能继续执行。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP