[实践OK]Shell逐行读取文件的3种方法while read line ;do echo $line; done < sort.txt,有谁知道在shell读取一个文本文件中的内容并赋值到一个变量
一行搞定:
效率最高:
#while read line
> do
> echo $line
> done < sort.txt
jack 1984
jack 1928
jack 19834
jack 1984
jack 1984
jack 1984
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
#cat sort.txt |while read LINE
> do
> echo $LINE
> done
jack 1984
jack 1928
jack 19834
jack 1984
jack 1984
jack 1984
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
#for line in $(cat sort.txt )
> do
> echo ${line}
> done
jack
1984
来自:https://www.cnblogs.com/mgzc-1508873480/p/7866915.html
效率最高:
#while read line
> do
> echo $line
> done < sort.txt
jack 1984
jack 1928
jack 19834
jack 1984
jack 1984
jack 1984
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
#cat sort.txt |while read LINE
> do
> echo $LINE
> done
jack 1984
jack 1928
jack 19834
jack 1984
jack 1984
jack 1984
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
xiangdong 1988
#for line in $(cat sort.txt )
> do
> echo ${line}
> done
jack
1984
来自:https://www.cnblogs.com/mgzc-1508873480/p/7866915.html
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1706/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2018-9-28 09:55
评论列表