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

时间:2021-04-21 16:18:50   收藏:0   阅读:27

 

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  为逐行读取, 可基于此方法在每行传递多个参数。

 

原文:https://www.cnblogs.com/liujiaxin2018/p/14684772.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!