逐行读取文件的Shell代码

2015-01-21 0 411
逐行读取文件的Shell代码

linux shell 按行循环读入文件方法

#!/bin/bash
 
printf "*************************************\n"
echo " cat file while read line"
cat one.log |while read line
do
    echo $line;
done
 
printf "*************************************\n"
echo "while read line <file"
while read line
do
    echo $line;
done <one.log
 
printf "*************************************\n"
echo "for line in cat test.txt"
SAVEIFS=$IFS
IFS=$(echo -en "\n")
for line in $(cat test.txt)
do
    echo $line;
done
IFS=$SAVEIFS

前二种方法可以分别简化成一行简短的代码

cat one.log|while read line;do echo $line;done
 
while read line; do echo $line; done<one.log

遇见资源网 shell 逐行读取文件的Shell代码 http://www.ox520.com/16796.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务