sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #100404
Re: Storke langsomt bash script
Martin Dupont Ahrentsen <martin@xxxxxxxxxxxx> writes:
> Jeg har et script som skal parse en en fil hvor den skal tjekke om
> nogle numre på nogle felter ligger indenfor nogle globale serier.
Du er et godt stykke på den anden side af hvor jeg ville vælge et
andet sprog end shell scripts.
> ----------------start cut af script----------------
>
> startno1=92080000001
> endno1=92081327500
>
> startno2=92085000001
> endno2=92085135000
>
> startno3=92085135000
> endno3=92085973000
>
> cd ${masterdatadir}
>
> for i in `cat t_pcl_ser`
> do
> testcustomerid=`echo $i | cut -d\| -f1`
> teststartno=`echo $i | cut -d\| -f2`
> testendno=`echo $i | cut -d\| -f3`
> testactiveflag=`echo $i | cut -d\| -f4`
> testprocflag001=`echo $i | cut -d\| -f5`
> testprocflag002=`echo $i | cut -d\| -f6`
> testprocflag003=`echo $i | cut -d\| -f7`
> testprocflag004=`echo $i | cut -d\| -f8`
> testcountrya2=`echo $i | cut -d\| -f9`
> testzip=`echo $i | cut -d\| -f10`
> testprocflag005=`echo $i | cut -d\| -f11`
En del af dit problem er at du starter 33 processer bare for at parse
en enkelt linje. Med bash kan du stoppe linjen i et array med lidt
smart brug af IFS.
OLD_IFS=$IFS
IFS="|"
line=($i)
IFS=$OLD_IFS
testcustomerid=${line[0]}
teststartno=${line[1]}
testendno=${line[2]}
testactiveflag=${line[3]}
testprocflag001=${line[4]}
testprocflag002=${line[5]}
testprocflag003=${line[6]}
testprocflag004=${line[7]}
testcountrya2=${line[8]}
testzip=${line[9]}
testprocflag005=${line[10]}
> if [ \( ${teststartno} -ge ${startno1} -a ${testendno} -le
> ${endno1} \) -o \( ${teststartno} -ge ${startno2} -a ${testendno} -le
> ${endno2} \) -o \( ${teststartno} -ge ${startno3} -a ${testendno} -le
> ${endno3} \) ]
> then
> echo
> "${testcustomerid}|${teststartno}|${testendno}|${testactiveflag}|${testprocflag001}|Y|Y|${testprocflag004}|${testcountrya2}|${testzip}|${testprocflag005}|"
>>> ${masterdatadir}/tmp/t_pcl_ser
> else
> echo ${i} >> ${masterdatadir}/tmp/t_pcl_ser
> fi
> done
>
> ----------------end cut af script----------------
//Makholm
Follow ups
References