shell读取文件的每一行
2013-11-01 08:50
246 查看
shell读取文件的每一行
首先装了cygwin,在win8.1下需要安装64位的,http://cygwin.com/setup-x86_64.exe
#!/bin/bash 很重要,必须加在最前面
有1.txt,内容如下:
1111
2222
3333 4444 555
写法一:
----------------------------------------------------------------------------
#!/bin/bash
while read line
do
echo $line
done < 1.txt
----------------------------------------------------------------------------
写法二:
----------------------------------------------------------------------------
#!/bin/bash
cat 1.txt | while read line
do
echo $line
done
----------------------------------------------------------------------------
写法三:
----------------------------------------------------------------------------
for line in `cat 1.txt`
do
echo $line
done
----------------------------------------------------------------------------
说明:
for逐行读和while逐行读是有区别的,如:
cat 1.txt
1111
2222
3333 4444 555
cat file | while read line; do echo $line; done
1111
2222
3333 4444 555
for line in $(<1.txt); do echo $line; done
1111
2222
3333
4444
555
两列读取:
#!/bin/bash
cat 1.txt | while read col1 col2
do
echo col1
echo col2
done
相关文章推荐
- shell:读取文件的每一行内容并输出
- (转)shell:读取文件的每一行内容并输出
- shell脚本:一次读取文件的一行【转】
- shell脚本:一次读取文件的一行,并输出
- Shell脚本一次读取文件中一行的2种写法
- shell读取文件的每一行
- shell 读取文件每一行
- shell 读取文件的每一行内容并输出
- shell脚本:一次读取文件的一行,并输出
- shell:读取文件的每一行内容并输出
- shell脚本,每次读取文件的一行,逐行读取并处理
- 操原作业(二)之在 Ubuntu 中编写一个shell从文件中读取每一行显示并统计总行数
- shell读取文件的每一行
- shell读取文件的一行
- shell:读取文件的每一行内容并输出
- shell读取文件的每一行
- shell:读取文件的每一行内容并输出
- shell读取文件每一行的方式
- shell脚本中一次读取文件中的一行
- shell读取文件的每一行(by 技术天空)