shell脚本-----按行读取文件
来源:互联网 发布:编辑书的软件 编辑:程序博客网 时间:2024/03/29 13:00
按行读取文件
#!/bin/bashecho "##### 方法 1 #####"while read line1doecho $line1done < $1echo "##### 方法 2 #####"cat $1 | while read line2doecho $line2doneecho "##### 方法 3 #####"for line3 in $(<$1)doecho $line3done
snail@ubuntu:5.read-line$ cat file.bin
hello world
this is 1
this is 2
this is 3
snail@ubuntu:5.read-line$ ./read-line.sh file.bin
##### 方法 1 #####
hello world
this is 1
this is 2
this is 3
##### 方法 2 #####
hello world
this is 1
this is 2
this is 3
##### 方法 3 #####
hello
world
this
is
1
this
is
2
this
is
3
hello world
this is 1
this is 2
this is 3
snail@ubuntu:5.read-line$ ./read-line.sh file.bin
##### 方法 1 #####
hello world
this is 1
this is 2
this is 3
##### 方法 2 #####
hello world
this is 1
this is 2
this is 3
##### 方法 3 #####
hello
world
this
is
1
this
is
2
this
is
3
使用for读取时,自动按空格作为间隔符。
如果输入文本每行中没有空格,则line在输入文本中按换行符分隔符循环取值.
如果输入文本中包括空格或制表符,则不是换行读取,line在输入文本中按空格分隔符或制表符或换行符特环取值.
可以通过把IFS设置为换行符来达到逐行读取的功能.
如果输入文本中包括空格或制表符,则不是换行读取,line在输入文本中按空格分隔符或制表符或换行符特环取值.
可以通过把IFS设置为换行符来达到逐行读取的功能.
IFS=$'\n'echo "##### 方法 3 #####"for line3 in $(<$1)doecho $line3done
- shell脚本-----按行读取文件
- shell脚本-----按行读取文件
- shell脚本-----按行读取文件-转
- shell脚本读取文件
- shell脚本按行读取文件并解析
- shell脚本按行读取文件并解析
- shell脚本按行读取文件并解析
- shell脚本按行读取文件并解析
- Shell脚本——按行读取文件
- shell脚本 - sed文件读取指定行
- shell脚本进行循环按行读取文件内容传参到其他shell脚本中
- shell脚本读取按行读取文本
- linux shell 读取文件脚本
- shell脚本之读取文件
- shell按行读取文件
- shell 读取文件行
- shell按行读取文件的方法
- Shell按行读取文件的方法
- oracle 创建 用户
- timus 1711.Code Names
- Ural-1044. Lucky Tickets. Easy!(简单题)
- linux网络 记住 关闭防火墙
- jQuery.extend 函数详解
- shell脚本-----按行读取文件
- Microsoft Visual Studio 2010 遇到了异常,可能是由某个扩展导致的
- JAVA设计模式笔记整理(四)
- HibernateCallback實現分頁查詢
- 内存对齐问题
- MYSQL导入导出.sql文件
- TopCoder SRM DIV2 Level 3: RelativelyPrimeSubset
- 笔试中的Singleton单例模式
- Tabular Model下的ADOMD.NET