awk getline

173346116.jpg

[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


你可能感兴趣的:(awk,getline)