我试图在循环中对每个供应商的一列求和。对于我的含糊之处,我深表歉意。我会尽力解释。假设从文件中读取每个供应商的文件中基于供应商名称总计标记为discount_amount 位置10 的字段。当我运行脚本时,我得到了expr: non-numeric argument
. discount_amount 是小数。以下是正在执行并接收错误的脚本部分:
############################################################################
#THIS SECTION WILL CAT THE FILE CREATED IN THE PREVIOUS STEP AND SEARCH THE
#SORTED FILE FOR LIKE VENDORS. THE VENDOR E-MAIL ADDRESS IS ALSO RETREIVED
#HERE AS IT IS AT THE END OF EACH RECORD. WHILE THE VENDOR REMAINS THE SAME,
#A NEW FILE IS CREATED WITH FIRST A COLUMN HEADING LINE, FOLLOWED BY THE DETAIL
#DATA FOR THE VENDOR. ONCE THE VENDOR CHANGES OR END OF THE FILE IS REACHED,
#THE PERL SCRIPT 'emailit.pl' IS USED TO SEND THE ILE TO THE VENDOR AS AN E-MAIL
#ATTATCHMENT. #6 and #7 determined not needed - 12/11/2015
# 1 vendor id 2 vendor name 3 invoice id 4 invoice date 5 invoice id 6 voucher id
# 7 payment id ref 8 payment date 9 paid amount 10 discount amount 11 backhaul freight
#12 gross amount 13 srd deduction 14 srd percent 15 emailid
#16 invoice period end date (maximum of 70 characters must be separated by ;
#############################################################################
#for test
export VENDOR_TEMP=/oracle/rdbms/usr/xxxxxx/scripts/temp/
echo "VENDOR_ID,VENDOR_NAME,INVOICE_ID,INVOICE_DATE,SCH_INVOICE_ID,PAYMENT_DATE,PAID_AMT,DISCOUNT_AMT,SCH_BACKHAUL_FRGHT,GROSS_AMT,DEDUCTION_AMT,SRD_PERCENT,EMAILID" > VENDOR_HDR
cat $VENDOR_FILE | while read LINE
do
VENDOR_NAME=`echo $LINE | awk -F, '{print $2}'`
touch $VENDOR_TEMP/$VENDOR_NAME
echo $LINE >> $VENDOR_TEMP/$VENDOR_NAME
done
VENDOR_LIST=`ls $VENDOR_TEMP`
echo "if there is a vendor with two or more entries in the vendor list file you may see a mv statement that states cannot access: No such file or directory" | tee -a $Log
for VENDOR_NAME in `echo $VENDOR_LIST`
do
DISCOUNT_TOTAL=0
INVOICE_DATE=''
VENDOR_ID=`awk -F, 'NR==1{print $1}' $VENDOR_TEMP$VENDOR_NAME`
EMAIL_ADDRESS=`awk -F, 'NR==1{print $15}' $VENDOR_TEMP$VENDOR_NAME`
INVOICE_NUMBER=$(awk -F, 'NR==1{print $16}' $VENDOR_TEMP$VENDOR_NAME)
# Read each line of the vendor file to get the invoice date and sum invoice totals
for f in $(cat $VENDOR_TEMP$VENDOR_NAME)
do
DISCOUNT_TOTAL=$(expr ${DISCOUNT_TOTAL} + $(echo $f | awk -F, '{print $10}'))
done
cat VENDOR_HDR $VENDOR_TEMP$VENDOR_NAME > VENDOR_TMP
mv VENDOR_TMP $VENDOR_TEMP$VENDOR_NAME
mv $VENDOR_TEMP$VENDOR_NAME $VENDOR_TEMP$VENDOR_NAME.csv
if [ "$EMAIL_ADDRESS" = '' ];then
./send_email.pl --sub "INVALID EMAIL ADDRESS PLEASE CORRECT $VENDOR_ID $VENDOR_NAME" --rec 'emailaddresses' --file "$VENDOR_TEMP$VENDOR_NAME.csv" --total $DISCOUNT_TOTAL --date $INVOICE_DATE --invoice $INVOICE_NUMBER
else
./send_email.pl --sub "$VENDOR_ID $VENDOR_NAME Schnuck Retail Deductions (SAS)" --send emailaddresses.com --rec [email protected] --file "$VENDOR_TEMP$VENDOR_NAME.csv" --total $DISCOUNT_TOTAL --date $INVOICE_DATE --invoice $INVOICE_NUMBER
fi
mv $VENDOR_TEMP$VENDOR_NAME.csv $SCH_ARCHIVE/$(basename $VENDOR_TEMP$VENDOR_NAME.csv).$FILEDATE
done
以下是正在读取的数据的示例:
122198,ConAgra_Foods_Co,SRD122198032915,16-MAR-15,0450287,25146609,213199,27-MAR-15,3767.01,77.77,0,3844.78,0,0,emailaddress.com,29-NOV-15
140214,Joy_Cone__Co,SRD140214032915,04-MAR-15,243395,25104588,212317,18-MAR-15,2971.16,60.64,0,3031.8,0,0,emailaddress.com;,29-NOV-15
140214,Joy_Cone__Co,SRD140214032915,04-MAR-15,243394,25104587,212317,18-MAR-15,2363.76,48.24,0,2412,0,0,emailaddress.com,29-NOV-15
147810,McCormick_Company,SRD147810032915,10-MAR-15,3784260,25143679,100141,18-MAR-15,17446.63,356.09,0,17802.72,0,0,emailaddress,29-NOV-15
147810,McCormick_Company,SRD147810032915,03-MAR-15,3777825,25112108,099510,11-MAR-15,4913.94,100.3,0,5014.24,0,0,emailaddress,29-NOV-15
147810,McCormick_Company,SRD147810032915,27-FEB-15,3775282,25098526,099330,09-MAR-15,7269.84,148.36,0,7418.2,0,0,emailaddress,29-NOV-15
147810,McCormick_Company,SRD147810032915,26-FEB-15,3773988,25098525,099155,06-MAR-15,4611.8,94.12,0,4705.92,0,0,emailaddress,29-NOV-15
147810,McCormick_Company,SRD147810032915,24-FEB-15,3770586,25081388,098931,04-MAR-15,9742.03,198.83,0,9940.86,0,0,emailaddress,29-NOV-15
159605,Nestle_Waters_of_North_America,SRD159605032915,18-JAN-15,4296435,24908423,210015,04-MAR-15,8772.68,0,0,8772.68,0,0,emailaddress,29-NOV-15
159605,Nestle_Waters_of_North_America,SRD159605032915,19-JAN-15,4397088,24908424,210015,04-MAR-15,5148,0,0,5148,0,0,emailaddress,29-NOV-15
答案1
由于模糊和不完整,您的问题仍然几乎无法回答。您尚未显示任何输入数据(根据要求)或任何代码(根据要求)。然而,你却泄露了一丝信息:
++ expr 0 + 496.8
expr: non-numeric argument
expr
不适用于非整数(即带小数点的数字)。您需要将数据转换为整数,或者使用处理非整数的计算器程序(bc
这是一个很好的方法)。