逐行读取文件的Shell代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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