linux shell 按行循环读入文件方法
转http://blog.csdn.net/hittata/article/details/7042779
- #/bin/bash
- printf "*************************************\n"
- echo " cat file whiel read line"
- cat test.txt |while read line
- do
- echo $line;
- done
- printf "*************************************\n"
- echo "while read line <file"
- while read line
- do
- echo $line;
- done <test.txt
- printf "*************************************\n"
- echo "for line in cat test.txt"
- SAVEIFS=$IFS
- IFS=$(echo -en "\n")
- for line in $(cat test.txt)
- do
- echo $line;
- done
- IFS=$SAVEIFS
注意:for line in $(cat test.txt) 当文件中有空格或者tab 时,一定要设置一下IFS变量。
linux shell 按行循环读入文件方法的更多相关文章
- linux shell获取show slave status方法
linux shell获取show slave status方法<pre>#!/bin/basharray=($(mysql -u数据库账号 -p数据库密码 -e "show s ...
- linux shell的输出效果修改方法(界面颜色)
文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置背景成为蓝色,前景白色, ...
- linux shell脚本调用java main方法 代码
#!/bin/sh # #该脚本为Linux下启动java程序的通用脚本.即可以作为开机自启动service脚本被调用, #也可以作为启动java程序的独立脚本来使用. # #Author: tuda ...
- secureCRT linux shell显示中文乱码 解决方法
引:有没有这样的经历: 1.在shell中直接查看包含中文的文件时,出现一堆火星文,不得不下载下来window看. 2.无法正常的在shell中输入中文. 3.make的时候输出一堆乱码. 以下是查阅 ...
- linux shell条件与循环举例
1. if/else 语句 语法: if condition; then commands;elif condition; then commands;else commands;fi 示例:需求:脚 ...
- 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 ...
- Linux Shell 只列出目录的方法
在实际应用中,我们有时需要仅列出目录,下面是 4 种不同的方法. 1. 利用 ls 命令的 -d 选项: $ ls -d */ Desktop/ pic/ shell/ src/ 2. 利用 ls 命 ...
- Linux shell逐行读取文件的方法
方法1:while循环中执行效率最高,最常用的方法. function while_read_line_bottom(){ while read line do echo $line done < ...
- linux shell实现 URL 编码/解码方法
(1)编码的两种方法 # echo '手机' | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g' # echo '手机' |tr -d '\n' |od ...
随机推荐
- WebService 的简单使用
简单介绍 WebService是一种跨语言,跨进程,跨机器的数据交互技术. SOAP:简单对象访问协议,通过XML数据交互的轻量级协议,WebService就是采用的这种协议 WSDL:web服务描述 ...
- Git Bash关键命令
1.默认目录是C:\Users\用户名 2.切换目录:$cd c:\\windows 3.切换到上级目录:cd ..,中间有空格 4.列出某目录所有文件,相当于DOS下的dir:ls c:\\wind ...
- yum localinstall 安装mysql8.0
MySQL :: MySQL 8.0 Reference Manual :: 2.5.1 Installing MySQL on Linux Using the MySQL Yum Repositor ...
- string unicode utf8 ascii in python and js
http://www.jb51.net/article/62155.htm http://www.cnblogs.com/dkblog/archive/2011/03/02/1980644.html ...
- 转!idea启动后发现tomcat前面出现红色或是灰色的问号
原博文地址:https://blog.csdn.net/z_zhy/article/details/83068168 直接在idea里 点击File------settings,在搜索框直接搜tomc ...
- (2.10)Mysql之SQL基础——约束及主键重复处理
(2.10)Mysql之SQL基础——约束及主键重复处理 关键词:mysql约束,批量插入数据主键冲突 [1]查看索引: show index from table_name; [2]查看有约束的列: ...
- git-【二】本地git操作提交、版本回退
一.创建版本库,提交文件 什么是版本库?版本库又名仓库,英文名repository,你可以简单的理解一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改,删除,Git都能跟踪,以便任 ...
- 一些动态规划问题的java实现
从上往下推公式,从下往上求解值. 一:矩阵链乘法,最小括号化方案,动态规划方程. 0 如果i=j m[i,j] ={ min[i,k]+m[k+1,j]+pi-1pkpj ...
- Kconfig文件说明
Kconfig的格式 下面截取/drivers/net下的Kconfig文件中的部分内容: # Network device configuration menuconfig NETDEVICES d ...
- Cannot find entry file index.android.js in any of the roots:[ Android ]
Changed the version of react project to a lower one from here npm install -g rninit rninit init [Pro ...