如何在Shell脚本中逐行读取文件

2021/4/26 7:27:50

本文主要是介绍如何在Shell脚本中逐行读取文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、创建一个名为“ example1.sh”的脚本,该脚本使用输入重定向和循环:

[root@localhost ~]# cat example1.sh 
#!/bin/bash
while read rows
do
  echo "Line contents are : $rows "
done < mycontent.txt


2、[root@localhost ~]# cat example2.sh 
#!/bin/bash
cat mycontent.txt | while read rows
do
  echo "Line contents are : $rows "
done


这篇关于如何在Shell脚本中逐行读取文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程