Sponsored Content
Top Forums Shell Programming and Scripting how to add up a total in a summary report? Post 302309764 by xiaojesus on Wednesday 22nd of April 2009 08:20:35 PM
Old 04-22-2009
Hi all , below i am suppose to key in and enter the daily sales in to the system.

and i am suppose to get the daily total sales and the grand total sales when i ask for summary listing
below is the code that i have write.. can any one help?

the function doesnt seems to bea ble to reconise the system day and promt me a syntaxerror..



Code:
#Enter and add in the Item detail, Item Price and Quantity Purchased into the system.
add_item()
{
  echo "Add Item: You will be prompted for 3 items:"
  echo "- Item Description, Unit Price, Quantity Purchased -"
  echo
  echo -en "Item Description:"
  read product
  echo -en "Unit Price:"
  read Unit_Price
  echo -en "Quantity:"
  read Quantity
  Date_Purchased=$(date +"%d %b %Y")  
  
  echo "${product}:${Unit_Price}:${Quantity}:${Date_Purchased}" >> $POS
}
#i am printing out all the daily sales in a day   print_dtotal
#i am printing out all the grand total sales of all days  print_gtotal
summary_items()
{
  
  print_dtotal
 
  print_gtotal
  
  print_dtotal | sort -f4| while read z
    do
        echo $z | cut -f4 -d' '
        return 0
    done
  echo
  echo -en "Press Enter to continue..."
  read
}
print_dtotal()
{
  count=0
  grep -i : $POS | cut -d: -f4 | sort -u | while read i
    do
        dtotal=0
    grep -i "$i" $POS | while read x
        do
            count=`expr $count + 1`
            temp1=`echo $x | cut -d: -f2 | cut -c2-`
            temp2=`echo $x | cut -d: -f3`
            temp3=`calcu_m $temp1 $temp2`
                        dtotal=`calcu_a $dtotal $temp3`
            n=`num_lines "$i"`
               if [ "${n}" -eq "${count}" ]; then
                echo  $i"        $"$dtotal
              fi
        done
    done 
}
print_gtotal()
{
  gtotal=0
  grep -i : $POS | while read x
    do
        temp1=`echo $x | cut -d: -f2 | cut -c2-`
        temp2=`echo $x | cut -d: -f3`
        temp3=`calcu_m $temp1 $temp2`
                gtotal=`calcu_a $gtotal $temp3`
        n=`num_lines "$i"`
           if [ "${n}" -eq "${count}" ]; then
            echo  "Grand Total      $"$gtotal
          fi
        count=`expr $count + 1`
    done 
}
calcu_a()        # add 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y1=`echo $2 | cut -d. -f1`
    y2=`echo $2 | cut -d. -f2`
    x1=`expr $x1 + $y1`
    x2=`expr $x2 + $y2`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}
calcu_m()        # multiply 2 decimal numbers $1 $2
{
    x1=`echo $1 | cut -d. -f1`
    x2=`echo $1 | cut -d. -f2`
    y=`echo $2`
    x1=`expr $x1 \* $y`
    x2=`expr $x2 \* $y`
    x3=`expr $x2 \/ 100`
    x1=`expr $x1 + $x3`
    x2=`expr $x2 \% 100`
    echo $x1"."$x2
}

 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print summary or the total disk usage of conf file

hey i want to print the summary or the total disk usage of the configuration files that are in the /etc directory printed in human-readable format. i think i got somewhere right as am using wc *.conf commands but i am unsure how to use to put it in human-readable format with the wc command. ... (13 Replies)
Discussion started by: stefanere2k9
13 Replies

2. Shell Programming and Scripting

Parse diff output into very detailed & summary report

Hello all; I'll try an explain my dilemma as best I can. But first some background: 1- I am suppose to compare a database to itself before and after changes; basically generate audit trail report. 2- This database contains "RULES" (the id field) that we use for transmitting files. 3 - The... (0 Replies)
Discussion started by: gvolpini
0 Replies

3. Linux

How to calculate total CPU usage from SAR report?

Hi, I want to calculate the total cpu usage from the sar report. Say for example, Linux 2.6.24-21-generic (blade10) 09/10/2012 04:54:36 PM CPU %user %nice %system %iowait %steal %idle 04:54:37 PM all 0.00 0.00 0.00 0.00 ... (1 Reply)
Discussion started by: rohitmd
1 Replies

4. Shell Programming and Scripting

Summary report csv file

Hello, I have 2 csv files with 4 columns each. file1.csv A, AA, AAA, AAAA B, BB, BBB, BBBB file2.csv C, CC, CCC, CCCC D, DD, DDD, DDDD I would like to use shell commands (sed, awk...) to copy the content of the 2 files (2x4 columns) into a final csv template file. Expected... (2 Replies)
Discussion started by: inMyZone35
2 Replies

5. Shell Programming and Scripting

Generate a Summary report

Hi All, Script to meet my requirement might be simpler for UINIX experts.. :) I need to generate an summary report in .txt file using shell script I have Reject directory in Unix server which contains all reject files for three diff categories- Presentation, Chapter and Scene Following... (3 Replies)
Discussion started by: Sakthikalluri
3 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 05:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy