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
SSH2_METHODS_NEGOTIATED(3)						 1						SSH2_METHODS_NEGOTIATED(3)

ssh2_methods_negotiated - Return list of negotiated methods

SYNOPSIS
array ssh2_methods_negotiated (resource $session) DESCRIPTION
Returns list of negotiated methods. PARAMETERS
o $session - An SSH connection link identifier, obtained from a call to ssh2_connect(3). RETURN VALUES
EXAMPLES
Example #1 Determining what methods were negotiated <?php $connection = ssh2_connect('shell.example.com', 22); $methods = ssh2_methods_negotiated($connection); echo "Encryption keys were negotiated using: {$methods['kex']} "; echo "Server identified using an {$methods['hostkey']} with "; echo "fingerprint: " . ssh2_fingerprint($connection) . " "; echo "Client to Server packets will use methods: "; echo " Crypt: {$methods['client_to_server']['crypt']} "; echo " Comp: {$methods['client_to_server']['comp']} "; echo " MAC: {$methods['client_to_server']['mac']} "; echo "Server to Client packets will use methods: "; echo " Crypt: {$methods['server_to_client']['crypt']} "; echo " Comp: {$methods['server_to_client']['comp']} "; echo " MAC: {$methods['server_to_client']['mac']} "; ?> SEE ALSO
ssh2_connect(3). PHP Documentation Group SSH2_METHODS_NEGOTIATED(3)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy