Chinaunix

标题: 求解释,不理解那,基础不行! [打印本页]

作者: kr_zhang    时间: 2011-03-06 18:48
标题: 求解释,不理解那,基础不行!
如题!

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

look

look

作者: chenbin200818    时间: 2011-03-06 19:25
无话可说  你还是找本书学习下把
作者: kr_zhang    时间: 2011-03-06 19:36
我就是找不到才提问的。
我认为4行后应该输出,但输出2行,这2行也没规律
作者: Shell_HAT    时间: 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.
作者: Shell_HAT    时间: 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

作者: leal402    时间: 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]$
作者: ywlscpl    时间: 2011-03-07 08:41
每行都触发一次处理流程
作者: kr_zhang    时间: 2011-03-07 08:54
{getline var;print $0,var}
awk读取一行后,getline 又读取了第二行
awk第三行, getline又读取了第四行。

我感觉这种用法,用的比较少吧。
直接读文件比较好 {"cat urfile"|getline ;print $0}
作者: blackold    时间: 2011-03-07 08:57
一刀砍死一个,再一刀又一个……菜刀的这种用法也不多啊。
作者: kr_zhang    时间: 2011-03-07 09:12
哈哈,了解。我的感觉好像太多了,而且还没什么用
作者: cjaizss    时间: 2011-03-07 12:41
哈哈,了解。我的感觉好像太多了,而且还没什么用
kr_zhang 发表于 2011-03-07 09:12



    什么太多了?
作者: Shell_HAT    时间: 2011-03-07 13:04
回复 8# kr_zhang

如果觉得getline不爽,就不要用它了:
  1. awk '{print $0}' urfile
复制代码

作者: Shell_HAT    时间: 2011-03-07 13:06
回复 10# kr_zhang


哈哈,赞同。我的感觉世界上的钱种类太多了,除了人民币,其它钱不是没什么用,而是根本从来就不用。
作者: kr_zhang    时间: 2011-03-07 13:19
回复 11# cjaizss


    这个是留给读者的想象,各有各的答案




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2