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(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 10:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy