-1

I am trying to sum a column for each vendor in a loop. I apologize for the vagueness. I will try to explain. It is suppose to read from a file and based on the vendor name total the field labeled discount_amount position 10 in the file for each vendor. When I run the script I get expr: non-numeric argument. The discount_amount is a decimal. Here is a the portion of the script that is executing and receiving the error:

############################################################################ 
#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 trudolf@schnucks.com --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

Here is a sample of the data being read:

 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
    "it isn't working" is a poor problem description: what is the input, what is your code supposed to do, and what does it actually do? – steeldriver Dec 17 '15 at 16:45
  • I apologiize for the vagueness. I will try to explain. It is suppose to read from a file and based on the vendor name total the field labelled discount_amount position 10 in the file for each vendor. When I run the script I get expr: non-numberic argument. The discount_amount is a decimal. Here is a sample line from the log: +++ echo 122198,ConAgra_Foods_Co,SRD122198032915,01-MAR-15,0364733,25080426,211469,13-MAR-15,23777.03,496.8,0,24273.83,0,0,######@company.com,29-NOV-15^M +++ awk -F, '{print $10}'^M ++ expr 0 + 496.8^M expr: non-numeric argument^M + DISCOUNT_TOTAL=^M – Sevenreindeer Dec 17 '15 at 20:12
  • Please edit your question to include that information, rather than adding it as a comment – steeldriver Dec 17 '15 at 20:21
  • Edit your question to post the full script, and an extract from the log that reproduces the problem. Pay attention to formatting, so that the line breaks are preserved. – Gilles 'SO- stop being evil' Dec 17 '15 at 23:43
0

Your question is still almost unanswerable due to vagueness and incompleteness.  You haven't shown any of your input data (as requested) or any of your code (as requested).  However, you let a glimmer of information leak through:

++ expr 0 + 496.8
expr: non-numeric argument

expr doesn't work on non-integers (i.e., numbers with a decimal point).  You need to either convert your data to integers or use a calculator program that handles non-integers (bc is a good one).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.