您的位置:首页 > 其它

awk getline

2013-05-15 17:29 169 查看


[root@localhost ~]# cat a.txt
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
0 j
[root@localhost ~]# awk '{while(getline>0) print $0,NF,FNR,NR}' a.txt
2 b 2 2 2
3 c 2 3 3
4 d 2 4 4
5 e 2 5 5
6 f 2 6 6
7 g 2 7 7
8 h 2 8 8
9 i 2 9 9
0 j 2 10 10
[root@localhost ~]# awk '{while(getline v>0) print v,NF,FNR,NR}' a.txt
2 b 2 2 2
3 c 2 3 3
4 d 2 4 4
5 e 2 5 5
6 f 2 6 6
7 g 2 7 7
8 h 2 8 8
9 i 2 9 9
0 j 2 10 10
[root@localhost ~]# awk '{while((getline < "a.txt")>0) print $0,NF,FNR,NR}' a.txt
1 a 2 1 1
2 b 2 1 1
3 c 2 1 1
4 d 2 1 1
5 e 2 1 1
6 f 2 1 1
7 g 2 1 1
8 h 2 1 1
9 i 2 1 1
0 j 2 1 1
[root@localhost ~]# awk '{while((getline v < "a.txt")>0) print v,NF,FNR,NR}' a.txt
1 a 2 1 1
2 b 2 1 1
3 c 2 1 1
4 d 2 1 1
5 e 2 1 1
6 f 2 1 1
7 g 2 1 1
8 h 2 1 1
9 i 2 1 1
0 j 2 1 1
[root@localhost ~]# awk '{while(("cat a.txt" | getline)>0) print $0,NF,FNR,NR}' a.txt
1 a 2 1 1
2 b 2 1 1
3 c 2 1 1
4 d 2 1 1
5 e 2 1 1
6 f 2 1 1
7 g 2 1 1
8 h 2 1 1
9 i 2 1 1
0 j 2 1 1
[root@localhost ~]# awk '{while(("cat a.txt" | getline v)>0) print v,NF,FNR,NR}' a.txt
1 a 2 1 1
2 b 2 1 1
3 c 2 1 1
4 d 2 1 1
5 e 2 1 1
6 f 2 1 1
7 g 2 1 1
8 h 2 1 1
9 i 2 1 1
0 j 2 1 1

本文出自 “notepad” 博客,请务必保留此出处http://sndapk.blog.51cto.com/5385144/1201041
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: