Shell按行读取文件的方法有很多,常见的三种方法如下:

要读取的文件:

 [root@mini05 -]# cat file.info 

写法一:

 [root@mini05 -]# cat read1.sh
#!/bin/bash
################ Version Info ##################
# Create Date: --
# Author: zhang
# Mail: zhang@xxx.com
# Version: 1.0
# Attention: 按行读取文件
################################################ # 加载环境变量
. /etc/profile
. ~/.bash_profile
. /etc/bashrc # 脚本所在目录及脚本名称
script_dir=$( cd "$( dirname "$" )" && pwd )
script_name=$(basename ${}) exec < ${script_dir}/file.info
while read line; do
echo "${line}"
done

写法二:

 [root@mini05 -]# cat read2.sh
#!/bin/bash
################ Version Info ##################
# Create Date: --
# Author: zhang
# Mail: zhang@xxx.com
# Version: 1.0
# Attention: 按行读取文件
################################################ # 加载环境变量
. /etc/profile
. ~/.bash_profile
. /etc/bashrc # 脚本所在目录及脚本名称
script_dir=$( cd "$( dirname "$" )" && pwd )
script_name=$(basename ${}) cat ${script_dir}/file.info | while read line;do
echo "${line}"
done

写法三:

 [root@mini05 -]# cat read3.sh
#!/bin/bash
################ Version Info ##################
# Create Date: --
# Author: zhang
# Mail: zhang@xxx.com
# Version: 1.0
# Attention: 按行读取文件
################################################ # 加载环境变量
. /etc/profile
. ~/.bash_profile
. /etc/bashrc # 脚本所在目录及脚本名称
script_dir=$( cd "$( dirname "$" )" && pwd )
script_name=$(basename ${}) while read line; do
echo "${line}"
done < ${script_dir}/file.info

Shell按行读取文件的3种方法的更多相关文章

  1. shell脚本,按行读取文件的几种方法。

    第一种方法用while实现按读取文件.[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 e ...

  2. shell按行读取文件

    这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑, ...

  3. python_基础学习_01_按行读取文件的最优方法

    python 按行读取文件 ,网上搜集有N种方法,效率有区别,先mark最优答案,下次补充测试数据 with open('filename') as file: for line in file: d ...

  4. Shell逐行读取文件的3种方法

    方法1:while循环中执行效率最高,最常用的方法. while read linedoecho $linedone  < filename 注释:这种方式在结束的时候需要执行文件,就好像是执行 ...

  5. php 读取文件的几种方法

    文件操作的三个步骤,打开,操作,关闭.$fopen=fopen(路径,方式),fwrite($fopen,写入的字符串);fclose($fopen). 其中打开方式有如下几种方式: 模式 描述 r ...

  6. shell 按行读取文件的内容

    test.py: #coding=utf- import subprocess compilePopen = subprocess.Popen('gcc haha',shell=True,stderr ...

  7. shell 按行读取文件

    #!/bin/bash count= //赋值语句,不加空格 cat test | while read line //cat 命令的输出作为read命令的输入,read读到的值放在line中 do ...

  8. python 逐行读取文件的三种方法

    方法一: 复制代码代码如下: f = open("foo.txt")             # 返回一个文件对象  line = f.readline()             ...

  9. shell总结:读取文件、参数、if、分割字符串、数组长度、空文件、变量赋值、多进程、按行切割文件、查看线程

    Reference: http://saiyaren.iteye.com/blog/1943207 1.     Shell  读取文件和写文件 for line in $(<top30000. ...

随机推荐

  1. mybatis逆向工程(MyBatis Generator)

    mybatis逆向工程(MyBatis Generator) 1. 什么是mybatis逆向工程 mybatis官方为了提高开发效率,提高自动对单表生成sql,包括 :mapper.xml.mappe ...

  2. anoconda包管理汇总

    anoconda默认的seaborn版本是0.8.1 seaborn的最新版本是0.9.0  并且已经没有0.8.1的文档了. 升级anoconda的seaborn版本 进入anoconda prom ...

  3. 使用JS模拟锚点跳转

    A-HTML锚点定义: 设置锚: <a href="#mao">&nsbp;</a> 设置点:(为了浏览器兼容性,id和name一起设置) < ...

  4. 第一册:lesson twenty seven。

    原文 :Mrs.smith's living room. Mrs.smith's living room is large. There is a television in the room. Th ...

  5. 【转载】Sqlserver中查询窗口显示行号

    在Sqlserver中编写语句的时候,有时候因为业务逻辑比较复杂,编写的语句会比较多,此时如果编辑器中显示代码的行号,则对于我们的语句编写有很好的辅助作用.sqlserver默认未开启行号显示功能,可 ...

  6. 多个微信小程序一个服务端架构

    由于某些特定的业务场景,当多个小程序需要一个服务端后台提供数据时,大家可能想到是HTTP路由.是的,实际上我们使用微服务的GateWay网关也是一样的,如下图微服务架构: 网关GateWay的作用在于 ...

  7. Java高并发 -- 并发扩展

    Java高并发 -- 并发扩展 主要是学习慕课网实战视频<Java并发编程入门与高并发面试>的笔记 死锁 死锁是指两个或两个以上的事务在执行过程中,因争夺锁资源而造成的一种互相等待的现象, ...

  8. meta标签的http-equiv与content解析

    meta是html语言head区的一个辅助性标签,以下是meta的http-equiv属性和content属性的一些介绍. http-equiv属性 指示服务器在发送实际的文档之前,要在传送给浏览器的 ...

  9. 【20190130】CSS-文字排版

    字间距:letter-space:**px: 禁止中文词内换行:给每个单词设置 white-space: nowrap;

  10. 关于处理注册表权限无法修改的问题(无法打开主键或注册表项unknown)

    CMD下(管理员) secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose 此命令可以生成报告, 任 ...