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 按行循环读入文件方法的更多相关文章

  1. linux shell获取show slave status方法

    linux shell获取show slave status方法<pre>#!/bin/basharray=($(mysql -u数据库账号 -p数据库密码 -e "show s ...

  2. linux shell的输出效果修改方法(界面颜色)

    文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置背景成为蓝色,前景白色, ...

  3. linux shell脚本调用java main方法 代码

    #!/bin/sh # #该脚本为Linux下启动java程序的通用脚本.即可以作为开机自启动service脚本被调用, #也可以作为启动java程序的独立脚本来使用. # #Author: tuda ...

  4. secureCRT linux shell显示中文乱码 解决方法

    引:有没有这样的经历: 1.在shell中直接查看包含中文的文件时,出现一堆火星文,不得不下载下来window看. 2.无法正常的在shell中输入中文. 3.make的时候输出一堆乱码. 以下是查阅 ...

  5. linux shell条件与循环举例

    1. if/else 语句 语法: if condition; then commands;elif condition; then commands;else commands;fi 示例:需求:脚 ...

  6. Linux shell for while 循环

    1.数字段形式for i in {1..10}do   echo $idone 2.详细列出(字符且项数不多)for File in 1 2 3 4 5 do     echo $File done ...

  7. Linux Shell 只列出目录的方法

    在实际应用中,我们有时需要仅列出目录,下面是 4 种不同的方法. 1. 利用 ls 命令的 -d 选项: $ ls -d */ Desktop/ pic/ shell/ src/ 2. 利用 ls 命 ...

  8. Linux shell逐行读取文件的方法

    方法1:while循环中执行效率最高,最常用的方法. function while_read_line_bottom(){ while read line do echo $line done < ...

  9. linux shell实现 URL 编码/解码方法

    (1)编码的两种方法 # echo '手机' | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g' # echo '手机' |tr -d '\n' |od ...

随机推荐

  1. 遍历DataSet

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  2. Pandas使用to_csv保存中文数据用Excel打开是乱码

    关于这个问题还是困扰了很久,我生成了一些样本数据,打算保存到csv文件,之后用pandas的命令: # data是DataFrame的格式 data.to_csv('./data/myfile.csv ...

  3. LightGBM值参数配置

    LightGBM 可以使用一个 pairs 的 list 或一个字典来设置参数: 1.Booster提升器的参数: param={'num_class':33, 'boosting_type':'gb ...

  4. Python开发【模块】:M2Crypto RSA加密、解密

    M2Crypto 模块 快速安装: # 环境centos7.0,提前装好openssl(自行百度安装),windows装不上,暂不考虑了 [root@localhost ~]# pip install ...

  5. HTTP错误 404.17–Not Found 请求的内容似乎是脚本,因而将无法有静态文件处理程序来处理

    解决方案:切换应用程序池的模式.

  6. Spring 小知识

    1:Advice环绕通知相当于  aop:before之类的 2:Mybatis执行流程: Configuration对象时运行项目时,就直接生成了. 2.1 通过XMLBuilder 解析XML,  ...

  7. t分布, 卡方x分布,F分布

    T分布:温良宽厚 本文由“医学统计分析精粹”小编“Hiu”原创完成,文章采用知识共享Attribution-NonCommercial-NoDerivatives 4.0国际许可协议(http://c ...

  8. 统计编程的框架与R语言统计分析基础——摘(1)

    清屏命令ctrl+L 一.基础 1.产生数据结构 a.直接输入 b.冒号,1:10 c.seq函数 d.rep函数 > 1:10 [1] 1 2 3 4 5 6 7 8 9 10 > 10 ...

  9. docker——三剑客之Docker Compose

    编排(Orchestration)功能是复杂系统实现灵活可操作性的关键.特别是在Docker应用场景中,编排意味着用户可以灵活的对各种容器资源实现定义和管理. 作为Docker官方编排工具,Compo ...

  10. iOS App迁移(App Transfer)注意点

    1.App迁移需要苹果审核吗? 答:不需要 2.App迁移需要多长时间? 答:迁移操作过程很快,A账号发出申请,B账号接收,几分钟时间.App Store 展示B账号相关信息可能几分钟,也可能有延迟几 ...