免费注册 查看新帖 |

Chinaunix

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

求解释,不理解那,基础不行! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-06 18:48 |只看该作者 |倒序浏览
如题!

未命名.jpg (26.66 KB, 下载次数: 4)

look

look

论坛徽章:
0
2 [报告]
发表于 2011-03-06 19:25 |只看该作者
无话可说  你还是找本书学习下把

论坛徽章:
0
3 [报告]
发表于 2011-03-06 19:36 |只看该作者
我就是找不到才提问的。
我认为4行后应该输出,但输出2行,这2行也没规律

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
4 [报告]
发表于 2011-03-06 19:37 |只看该作者
The getline function is used to read another line of input. Not only can getline read from the
regular input data stream, it can also handle input from files and pipes.

The getline function is similar to awk's next statement. While both cause the next input line to be
read
, the next statement passes control back to the top of the script. The getline function gets the
next line without changing control in the script.

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
5 [报告]
发表于 2011-03-06 19:40 |只看该作者
回复 3# kr_zhang


看出规律没?
#cat urfile
1
2
3
4
5
6
7
8
9
10
#awk '{getline var; print var}' urfile
2
4
6
8
10

论坛徽章:
0
6 [报告]
发表于 2011-03-06 19:52 |只看该作者
理解当前处理的地址是关键。

[oracle@Centos temp]$ awk -f a.awk  tmp
aa bb cc dd
a b c d
! @ # $
aa bb cc dd
[oracle@Centos temp]$ cat a.awk
#!/bin/awk

{print ; getline var ; print var}
[oracle@Centos temp]$ cat tmp
aa bb cc dd
a b c d
! @ # $
aa bb cc dd
[oracle@Centos temp]$

论坛徽章:
0
7 [报告]
发表于 2011-03-07 08:41 |只看该作者
每行都触发一次处理流程

论坛徽章:
0
8 [报告]
发表于 2011-03-07 08:54 |只看该作者
{getline var;print $0,var}
awk读取一行后,getline 又读取了第二行
awk第三行, getline又读取了第四行。

我感觉这种用法,用的比较少吧。
直接读文件比较好 {"cat urfile"|getline ;print $0}

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
9 [报告]
发表于 2011-03-07 08:57 |只看该作者
一刀砍死一个,再一刀又一个……菜刀的这种用法也不多啊。

论坛徽章:
0
10 [报告]
发表于 2011-03-07 09:12 |只看该作者
哈哈,了解。我的感觉好像太多了,而且还没什么用
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP