for循环和while循环按行读取:
示例:
#! /bin/bash
# 适用于工作日志文本中某特殊列值处理
awk '{print $3}' data.txt > mydata.txt # 取第三列的值保存
len = $(cat data.txt | wc -l) # 文本行数计算
i = 1
while (( i < len+1 )):
do
sed -n ${i}p mydata.txt
# insert your code to do something
let i++
done
for line in `cat mydata.sh`
do
echo $line
# insert your code to do something about line
done
for line in $(cat mydata.sh)
do
echo $line
# insert your code to do something about line
done
while read -r line
do
echo $line
# insert your code to do something about line
done < mydata.txt # mydata.txt作为标准输入去被读取