写法一:

----------------------------------------------------------------------------

#!/bin/bash

while read line

do

echo $line

done < filename(待读取的文件)

----------------------------------------------------------------------------

写法二:

----------------------------------------------------------------------------

#!/bin/bash

cat filename(待读取的文件) | while read line

do

echo $line

done

----------------------------------------------------------------------------

写法三:

----------------------------------------------------------------------------

for line in `cat filename(待读取的文件)`

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

转自:http://hi.baidu.com/7636553/item/8476a5cdd8b5bf13b67a2433

shell读取文件的每一行的更多相关文章

  1. shell读取文件的每一行内容并输出【转】

    写法一: #!/bin/bash while read line do echo $line done < file(待读取的文件) 写法二: #!/bin/bash cat file(待读取的 ...

  2. (转)shell:读取文件的每一行内容并输出

    写法一:----------------------------------------------------------------------------#!/bin/bashwhile rea ...

  3. shell 读取文件的每一行内容并输出

    (1)#!/bin/bash while read linedo    echo $linedone < file (2)#!/bin/bash cat file  | while read l ...

  4. shell 读取文件的每一行

    1.使用while #!/bin/bash while read line do echo $line done < file.txt #!/bin/bash cat file.txt | wh ...

  5. shell读取文件第一行和最后一行,小数的运算比较

    1. 读取文件的第一行:head -n +1 file.txt 读取文件的最后一行: tail -n -1 file.txt echo 12:30:55 | cut -d: -f 1 结果为12,意思 ...

  6. shell读取文件内容并进行变量赋值

    需求: shell读取文件内容,然后把内容赋值给变量然后进行字符串处理 实现: dataline=$(cat /root/data/data.txt) echo $dataline

  7. 登录shell与非登录shell读取文件过程

    登录shell与非登录shell读取文件过程登录:/etc/profile→/etc/profile.d/*.sh        ~/.bash_profile非登录:~/.bash_profile→ ...

  8. shell读取文件内容

           Shell脚本,执行解释速度快.代码简单易于理解.在shell代码编写过程中,经常会用到读取文件内容. 写法一: ------------------------------------ ...

  9. linux 循环读取文件的每一行

    在Linux中有很多方法逐行读取一个文件的方法,其中最常用的就是下面的脚本里的方法,而且是效率最高,使用最多的方法.为了给大家一个直观的感受,我们将通过生成一个大的文件的方式来检验各种方法的执行效率. ...

随机推荐

  1. Spring+Struts集成(第二种方案)

    在上一篇文章中我们了解到了第一种Spring跟Struts集成的方案,但此集成方案的不足是WEB层中知道Spring的相关内容,因为需要去主动的查找对象:BeanFactory.方案二便是通过依赖注入 ...

  2. POJ 1511 Invitation Cards 正反SPFA

    题意:学生从A站到B站花费C元,将学生每天从‘1’号站送往其它所有站,再从所有站接回到‘1’号站,问着个过程最小花费是多少. 思路:因为数据很大所以要用SPFA,因为不仅要从1点连接各个点还要从各个点 ...

  3. Permission denied: user=xxj, access=WRITE, inode="user":hadoop:supergroup:rwxr-xr-x

    在windows中运行eclipse时报错Permission denied: user=xxj, access=WRITE, inode="user":hadoop:superg ...

  4. git@osc使用教程

    http://my.oschina.net/openswc/blog/142321 Git初体验 http://my.oschina.net/dxqr/blog/134811 网友整理的git@osc ...

  5. C语言5种存储区域

    C语言5种存储区域 转发至:http://www.mamicode.com/info-detail-927635.html 系统为了管理内存 把内存划分了几个区域 1> 栈区 栈区之中的数据在栈 ...

  6. Delph组件如何使用自己的图标(转)

    源:http://blog.csdn.net/henreash/article/details/7298451

  7. 二叉树查找(C#)

    参考文章: http://www.cnblogs.com/huangxincheng/archive/2012/07/21/2602375.html http://www.cnblogs.com/xi ...

  8. css中元素水平垂直居中4种方法介绍

    table-cell轻松设置文本图片水平垂直居中 让一个元素垂直居中的思路:把这个元素的容器设置为table-cell,也就是具有表格单元格的特性,再使用vertical-align(这个属性对blo ...

  9. iOS下bound,center和frame

    本文转发至:http://www.xuebuyuan.com/1846606.html 在写程序的时候发现,iOS下的坐标.位置很容易弄乱,特别是在不同的坐标系统中,必须完成弄明白一些概念才能做相应的 ...

  10. Docker Swarm集群

    Docker Swarm集群 IP 10.6.17.11  管理节点 IP 10.6.17.12   节点A IP 10.6.17.13   节点B IP 10.6.17.14   节点C 安装 Sw ...