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 ...
随机推荐
- 【NotePad++】使用指南
身为一名程序员,这绝对是很常用的工具,但是你真的用了他的全部功能么? 教程参考: [crifan 推荐]轻量级文本编辑器,Notepad 最佳替代品:Notepad++ 注:一个很详细的教程,虽然老, ...
- asp.net 下载文件几种方式
protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一个新的方法TransmitFile来解决使 ...
- php最全基础,数组,函数,超全局变量,时间,回话,文件,php操作mysql
共享一份学习php最全基础语法知识的笔记 原文链接:http://www.cnblogs.com/oscn/p/3607757.html:略有修改 http://www.cnblogs.com/l ...
- pandas的DataFrame用法
用来生成DataFrame数据 1.说明: class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=F ...
- Servlet + JSP 时代
Spring,Django,Rails,Express这些框架技术的出现都是为了解决什么问题,现在这些框架都应用在哪些方面? - 知乎 https://www.zhihu.com/question/2 ...
- Android-aidl, binder,surfaceview
http://blog.csdn.net/stonecao/article/details/6425019 http://www.cnblogs.com/linucos/archive/2012/05 ...
- Linux环境下proc的配置c/c++操作数据库简单示例
在虚拟机上装了oracle11g数据库,原本想利用c/c++学习操作数据库.结果感觉摊上了一个大坑.从安装好oracle数据库到配置好proc的编译选项整整花了二天.但让我意识到自己自己几点薄弱:1. ...
- proc_create函数内幕初探
一直以为PROC文件系统很是晦涩难懂,平时仅仅是使用它,不愿意去触碰内核中的具体实现.今天突发奇想,想看看里面究竟是怎么实现的,结果……真是大跌眼镜,没想到里面并不复杂 关于PROC文件系统的功能以及 ...
- mysql join实现方式
1. nested loop join 分别从两个表读一行数据进行两两对比,复杂度是n^2 2. block nested loop join 分别从两个表读很多行数据,然后进行两两对比,复杂度也是n ...
- andorid ListView和GirdView 与ScrollView 冲突
1.listview解决方法 public static void setListViewHeightBasedOnChildren(ListView listView) { if(listView ...