shell按行读取文件的三种方法
在shell编程中,用shell脚本实现文件的按行读取,方法有很多,这里分享三个方法。
1,shell按行读取文件 方法一:
while read line
do
echo $line
done < filename(待读取的文件)
2,shell按行读取文件 方法二:
cat filename(待读取的文件) | while read line
do
echo $line
done
3,shell按行读取文件 写法三:
do
echo $line
done
说明:
for逐行读和while逐行读是有区别的。
例如:
$ cat file
1111
2222
3333 4444 555
$ cat file | while read line; do echo $line; done
1111
2222
3333 4444 555
$ for line in $(<file); do echo $line; done
1111
2222
3333
4444
555
您可能感兴趣的文章:
shell按行读取文件的三种方法
inux shell初级入门教程
PHP按行读取文件时如何删除换行符
更改linux用户登录shell的方法
bash shell脚本执行的几种方法
python shell是什么
crontab调用shell无法读取环境变量的解决办法
了解shell的作用及种类
linux shell流程控制语句(if、for、while、case语句实例)
python和shell像吗