码迷,mamicode.com
首页 > 系统相关 > 详细

linux shell 按行循环读入文件方法

时间:2014-08-09 15:34:58      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:blog   http   文件   for   art   ar   linux   line   

http://blog.csdn.net/hittata/article/details/7042779

  1. #/bin/bash  
  2. printf "*************************************\n"  
  3. echo " cat file whiel read line"  
  4. cat test.txt |while read line  
  5. do  
  6.   echo $line;  
  7. done  
  8. printf "*************************************\n"  
  9. echo "while read line <file"  
  10. while read line  
  11. do  
  12.   echo $line;  
  13. done <test.txt
  14. printf "*************************************\n"  
  15. echo "for line in cat test.txt"  
  16. SAVEIFS=$IFS  
  17. IFS=$(echo -en "\n")  
  18. for line in $(cat test.txt)  
  19. do  
  20.   echo  $line;  
  21. done  
  22. IFS=$SAVEIFS 

注意:for line in $(cat test.txt)   当文件中有空格或者tab 时,一定要设置一下IFS变量。

linux shell 按行循环读入文件方法,布布扣,bubuko.com

linux shell 按行循环读入文件方法

标签:blog   http   文件   for   art   ar   linux   line   

原文地址:http://www.cnblogs.com/alex-blog/p/3900896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!