我需要将文件“tmpcsv2”中的一组变量与“uniq_id”中的变量进行比较,我将详细介绍下面的文件。
tmpcsv2 -> 此文件由另一个脚本“script1”更新,每次运行“script1”都会更新(不附加)“tmpcsv2”中的新变量。没有。变量的个数可能是 1 并且可以达到 200。
eg:
2042344352
2470697747
2635527510
3667769962
uniq-id -> 这是一组固定的变量(大约 10 万个)
(Business Name,Job ID,Job Size)
biz,1000036446,225210640
biz,100006309,6710840
biz,1000069211,2084019000
biz,1000118720,34194040
biz,1000150241,212322636
我正在使用'for'循环+'if'来比较它们,如下所示,有没有更简单或更快(影响更小)的方法?当我运行它时,需要很长时间才能输出结果。打印命令仅用于测试,稍后将删除!
****Part of a bigger script****
amt=0
mjc=0
for jbid in `cat tmpcsv2` #Pick ID for match & calculation
do
printf "Checking ID $jbid\n" >> Acsv3.tmp
for bsid in `cat uniq_id` #Matching jobs & size calulation
do
ckid=`echo $bsid | cut -d "," -f2` #ckid is the ID to check
jbsiz=`echo $bsid | cut -d "," -f3` #size of the ID
if [ $jbid == $ckid ]
then
printf "Matched at $ckid\n" #Print on Match found
printf "Valid -> $jbid\n" >> Bcsv3.tmp
((mjc++)) #Increment Matched Job Count
amt=$((amt+jbsiz)) #Add size of matched jobs
break
else
printf "No Match at $cksid\n" #No matches
fi
done
printf "Check for ID $jbid done\n" >> Acsv3.tmp
printf "Matched $mjc jobs with combined size of $amt\n" >> Acsv3.tmp
done
****End of Comparision****