shell:读取文件的每一行内容并输出

Posted 拾月凄辰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell:读取文件的每一行内容并输出相关的知识,希望对你有一定的参考价值。

写法一:输入重定向

1 #!/bin/bash
2 
3 while read line
4 do
5     echo $line
6 done < file(待读取的文件)

 

写法二:管道命令

1 #!/bin/bash
2 
3 cat file(待读取的文件) | while read line
4 do
5     echo $line
6 done

 

写法三:

1 for line in `cat file(待读取的文件)`
2 do
3     echo $line
4 done

 

以上是关于shell:读取文件的每一行内容并输出的主要内容,如果未能解决你的问题,请参考以下文章