linux - 脚本持续运行数小时
问题描述
我正在尝试计算文件第 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
解决方案
将 /dev/null 添加到您的查找结果中:
findresult="$(find $pathname -type f ( .... )) /dev/null"
因此, sed 将获得额外的空白来处理,而不是等待用户输入
推荐阅读
- xslt - xslt 从外部文档复制属性
- docker - 如何在 Azure Service Fabric 中为 docker 容器指定命令行参数
- python - 为 3 个字符串创建一个 for 循环
- vue.js - 将 Vue 组件作为入口点而不是 main.js
- c# - C# MVC,Action Method 不从 QueryString 读取参数
- ruby-on-rails - rails 上未定义的方法 `load_defaults' 生成迁移和 rails 控制台
- symfony - Symfony 代码在不同域上的不同项目之间的可维护性
- java - 在不运行程序的情况下计算
- c - 在 Linux 中,如何在 putty 中与其他人聊天,而不是 sudo
- android - 检索 downloadURL.result 时应用程序崩溃