Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6091744
  • 博文数量: 2759
  • 博客积分: 1021
  • 博客等级: 中士
  • 技术积分: 4091
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-11 14:14
文章分类

全部博文(2759)

文章存档

2019年(1)

2017年(84)

2016年(196)

2015年(204)

2014年(636)

2013年(1176)

2012年(463)

分类:

2012-07-08 07:46:04

原文地址:shell按行读取文件的方法 作者:icybay

写法一:

----------------------------------------------------------------------------

#!/bin/bash

 

while read line

do

    echo $line

done < filename(待读取的文件)

----------------------------------------------------------------------------

 

写法二:

----------------------------------------------------------------------------

#!/bin/bash

 

cat filename(待读取的文件) | while read line

do

    echo $line

done

----------------------------------------------------------------------------

 

写法三:

----------------------------------------------------------------------------

for line in `cat filename(待读取的文件)`

do

    echo $line

done

----------------------------------------------------------------------------

 

说明:

for逐行读和while逐行读是有区别的,如:

$ cat file

1111

2222

3333 4444 555

 

$ cat file | while read line; do echo $line; done

1111

2222

3333 4444 555

 

$ for line in $(

1111

2222

3333

4444

555

转自:

阅读(1143) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~