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. [转]docker 部署 mysql + phpmyadmin 3种方法

    本文转自:https://blog.csdn.net/Gekkoou/article/details/80897309 方法1: link # 创建容器 test-mysql (千万别用 mysql: ...

  2. [转]RPA流程自动化-Blueprism认证考试介绍

    本文转自:https://www.cnblogs.com/digod/p/9190186.html RPA流程自动化-Blueprism认证考试介绍 接触RPA有一段时间了,几种RPA相关工具也都试用 ...

  3. input type=file 上传文件样式美化(转载)

    input type=file 上传文件样式美化 来源:https://www.jianshu.com/p/6390595e5a36 在做input文本上传时,由于html原生的上传按钮比较丑,需要对 ...

  4. SpringBoot+kafka+ELK分布式日志收集

    一.背景 随着业务复杂度的提升以及微服务的兴起,传统单一项目会被按照业务规则进行垂直拆分,另外为了防止单点故障我们也会将重要的服务模块进行集群部署,通过负载均衡进行服务的调用.那么随着节点的增多,各个 ...

  5. Netty实战一之异步和事件驱动

    Netty是一款异步的事件驱动的网络应用程序框架,支持快速地开发可维护的高性能的面向协议的服务器和客户端. 使用Netty你可以并不是很需要网络编程.多线程处理.并发等专业Java知识的积蓄. Net ...

  6. Java学习笔记之——Manth类和String类

    (1) Math:常用的数学运算,都是静态方法 方法摘要 static double abs(double a) 返回 double 值的绝对值. static float abs(float a) ...

  7. software testing

    Software Testing Software testing is the process of evaluation a software item to detect differences ...

  8. 汇编语言--微机CPU的指令系统(五)(位操作指令)

    (6) 位操作指令 1.位扫描指令(Bit Scan Instruction) 指令的格式:BSF/BSR Reg, Reg/Mem ;80386+ 受影响的标志位:ZF 位扫描指令是在第二个操作数中 ...

  9. 有序列表ol,无序列表ul,定义列表dl

    ====================非常重要=================无序列表ul中有一个type属性四个属性值type="disc" 实心圆点(默认) type=&q ...

  10. gulp插件构建项目 压缩js、css、image、zip、web服务、跨域等插件

    推荐一个很好文: https://github.com/lin-xin/blog/issues/2 匹配符 *.**.!.{} gulp.src('./js/*.js') // * 匹配js文件夹下所 ...