linux系统中 while read逐行读取数据

 

1、测试for  cat

[root@PC3 test]# cat a.txt
01 02 03
06 07 08
11 12 13
16 17 18
[root@PC3 test]# for i in `cat a.txt`; do echo $i ; done
01
02
03
06
07
08
11
12
13
16
17
18

 

2、测试while  read

[root@PC3 test]# cat a.txt
01 02 03
06 07 08
11 12 13
16 17 18
[root@PC3 test]# cat a.txt | while read i; do echo $i; done
01 02 03
06 07 08
11 12 13
16 17 18

while read  为逐行读取, 可基于此方法在每行传递多个参数。

 

posted @ 2021-04-21 13:06  小鲨鱼2018  阅读(1371)  评论(0编辑  收藏  举报