LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 812|回复: 1

问个awk中根据文档特定内容赋值的问题? z

[复制链接]
发表于 2007-6-15 20:16:59 | 显示全部楼层 |阅读模式
譬如处理这样的一个文档:

  1. [...any lines comprised of any characters may be here]
  2. #The variables are given in the third line below this line:
  3. [random first line]
  4. [random second line]
  5. 111  222  1000 ...
  6. [blabla...]
复制代码


想把上面"#The variables are given in the third line below this line:"下数第三行中的三个数分别赋值,如 A=111,B=222, C=1000,...

怎么实现呢?模式匹配后如何下数几行呢?
发表于 2007-7-10 20:41:51 | 显示全部楼层
  1. awk -v times=3 '{if(times==0){A=$1;B=$2;C=$3};if($0~/^#The variables/)ok=1;if(ok==1)times-=1;};END{printf("A=%d\nB=%d\nC=%d\n",A,B,C)}' Yourfile
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

快速回复 返回顶部 返回列表