首页 > 解决方案 > 脚本持续运行数小时

问题描述

我正在尝试计算文件第 2 行和第 3 行中分隔符(分号、逗号或管道)的数量。如果计数不匹配,则文件应移至被拒绝的文件夹。当文件位于“pathname=/opt/interfaces/sample_check/mvfiles/inbox”位置时,脚本工作正常。但是,当文件不在该位置时,脚本会持续运行数小时,直到强制中止它。我错过了什么,你能帮忙吗?

pathname=/opt/interfaces/sample_check/mvfiles/inbox

findresult=$(find $pathname -type f ( -name "messagemulti.csv" -or -name "messagesemi.txt" -or -name "comma2.txt" -or -name "messagepipe.txt" -or -name "tokkalodi.txt" -or -name "ADMC_POSITION-LT3213.csv" -or -name "DMC_CASHFLOW248.csv" -or -name "ADMC_EQBASKET-WEIGHTS_52387.csv" -or -name "ADMC_POSITION-DDD7.csv" -or -name "ADMC_POSITION-DDD7.csv" ))


Count=`sed -n 2p $findresult | tr '[,]' '\n' | tr '[|]' '\n' | tr '[;]' '\n' | wc -l`
Count2=`sed -n 3p $findresult | tr '[,]' '\n' | tr '[|]' '\n' | tr '[;]' '\n' | wc -l`

echo $Count
echo $Count2
#if the delimiter count from the 2nd line and 3rd line doesnt match the    file will move to the rejected folder
if [ $Count != $Count2 ]

 then echo "Mis Match"

 mv $findresult /opt/interfaces/sample_check/mvfiles/reject
 else echo "Match"
 exit
 fi

标签: linuxshellunix

解决方案


将 /dev/null 添加到您的查找结果中:

findresult="$(find $pathname -type f ( .... )) /dev/null" 

因此, sed 将获得额外的空白来处理,而不是等待用户输入


推荐阅读