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 ...
随机推荐
- 170526、spring 执行定时任务
Spring 定时任务之 @Scheduled cron表达式 一.使用 Spring配置文件xmlns加入 xmlns:task="http://www.springframework.o ...
- sqlserver如何读写操作windows系统的文件
DECLARE @object int DECLARE @hr int DECLARE @src varchar(255), @desc varchar ...
- python基础之协程函数、列表表达式、生成器表达式
一.协程函数 协程函数的定义?如果在一个函数内部yield的使用方式是表达式形式的话,如x=yield,那么该函数称为协程函数 协程函数补充: def init(func): def wrapper( ...
- 【css a标签 鼠标悬浮时变手型】
<a href="#" style="cursor:pointer">
- Day19 客户关系系统实战
day19 今日内容 Service事务 客户关系管理系统 Service事务 在Service中使用ThreadLocal来完成事务,为将来学习Spring事务打基础! 1 DAO中的事务 ...
- mysql 约束条件 not null与default
not null与default 是否可空,null表示空,非字符串not null - 不可空null - 可空 use db4: 默认值,创建列时可以指定默认值,当插入数据时如果未主动设置,则自动 ...
- 在一台server上部署多个Tomcat
版权声明: https://blog.csdn.net/u011518709/article/details/27181665 在一台server上配置多个Tomcat的方法: 这几天因为在研究OGS ...
- ROS 命令学习记录
#catkin_init_workspace //just get CMakeList.txt #catkin_make //增加了信文件夹 build和devel #Catkin_creat_pk ...
- WebDriver API 实例详解(四)
三十一.使用页面的文字内容识别和处理新弹出的浏览器窗口 被测试网页的HTML源码: <html> <head> <meta charset="UTF-8&quo ...
- maven解决“Could not calculate build plan”问题
错误提示如下:(eclipse+maven) Could not calculate build plan: Failure to transfer org.apache.maven.plugins: ...