【发布时间】:2017-08-07 08:22:16
【问题描述】:
我正在尝试在 KSH 环境中编写一个 bash 脚本,该脚本将遍历源文本文件并按行块处理它
到目前为止,我已经想出了这段代码,虽然它似乎无限期地运行,因为如果要求检索源文本文件中的行之外的行,tail 命令不会返回 0 行
i=1
while [[ `wc -l /path/to/block.file | awk -F' ' '{print $1}'` -gt $((i * 1000)) ]]
do
lc=$((i * 1000))
DA=ProcessingResult_$i.csv
head -$lc /path/to/source.file | tail -1000 > /path/to/block.file
cd /path/to/processing/batch
./process.sh #This will process /path/to/block.file
mv /output/directory/ProcessingResult.csv /output/directory/$DA
i=$((i + 1))
done
在启动上述脚本之前,我执行了手动“第一次注入”:head -$lc /path/to/source.file | tail -1000 > /path/to/temp.source.file
您知道如何在处理完源文件的最后几行后让脚本停止吗?
提前谢谢大家
【问题讨论】: