Vertical total and listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vertical total and listing
# 8  
Old 07-18-2011
Hi Pravin27,
Thanks Pravin27 for your reply , but Sorry , what I wanted is , if the sum total of the particular named person amount is equal to or greater then the given total (say in my example >= 3000000), then print all the detail , I am trying to get back the all details by the last line of my code where I have put # at present ,but failed to get the correct data .

(1) By using array I am sorting the data where the DOB and Name are same and if the person's name is repeated then only those records are extracted.
(2) Using awk to sum the Amount ,
(3) After the summing, I want the full details if the sum amount is equal to or
greater then the replied in the begining of the code.

So I wanted if any one can show where I am making mistake? Smilie
# 9  
Old 07-19-2011
Try like this, Read input file twice
Code:
awk 'NR==FNR{n[$4]+=$3;next} n[$4]>=3000000{print}' infile infile


Last edited by pravin27; 07-19-2011 at 01:48 AM..
# 10  
Old 07-20-2011
Hi Pravin27 ,
Thanks lot for your reply, I tried your code , twice the input file , but not getting the out put at all . Nothing in output.Thanks once agaiin . I think The vertical total and then getting the full details by awk prog may not be possible.??

Thank you very much for sparing time for me.
# 11  
Old 07-20-2011
See the below code,
Code:
$cat infile

Code:
voucher    DOB           amount    name                              type
======   =======    =======  ==================   ===
37836452        1/13/1961       125000  ASHUTOSH        65
37836505        1/13/1961       500000  ASHUTOSH        49
37836455        1/13/1961       100000  ASHUTOSH        65
37836488        1/13/1961       250000  ASHUTOSH        75
37836473        1/13/1961       125000  ASHUTOSH        49
37836478        1/13/1961       250000  ASHUTOSH        49
37836519        1/13/1961       150000  ASHUTOSH        49
37836437        1/13/1961       500000  ASHUTOSH        49
37836461        1/13/1961       125000  ASHUTOSH        65
37836477        1/13/1961       250000  ASHUTOSH        65
37836486        1/13/1961       250000  ASHUTOSH        65
37836513        1/13/1961       500000  ASHUTOSH        65
37836431        1/13/1961       125000  ASHUTOSH        65
37836427        5/31/1991       350000  JOHNSON 75
37836470        5/31/1991       125000  JOHNSON 75
37836511        5/31/1991       62500   JOHNSON 75
37836520        5/31/1991       500000  JOHNSON 75
37836484        5/31/1991       200000  JOHNSON 75
37836435        5/31/1991       250000  JOHNSON 75
37836433        5/31/1991       150000  JOHNSON 65
37836482        5/31/1991       100000  JOHNSON 78
37836516        5/31/1991       100000  JOHNSON 65
37836497        5/31/1991       62500   JOHNSON 65
37836453        5/31/1991       375000  JOHNSON 75
37836506        7/12/1983       125000  LEENA   75
37836499        7/12/1983       125000  LEENA   75
37836507        7/12/1983       115000  LEENA   75
37836521        7/12/1983       250000  LEENA   65
37836465        7/12/1983       62500   LEENA   65
37836489        7/12/1983       500000  LEENA   49
37836459        7/12/1983       62500   LEENA   65
37836429        7/12/1983       250000  LEENA   65
37836436        7/12/1983       500000  LEENA   65
37836447        7/12/1983       500000  LEENA   65
37836476        8/12/1987       250000  MATHEWS         65
37836469        8/12/1987       100000  MATHEWS         75
37836454        8/12/1987       500000  MATHEWS         75
37836460        8/12/1987       375000  MATHEWS         75
37836522        8/12/1987       125000  MATHEWS         65
37836467        8/12/1987       62500   MATHEWS         65
37836446        8/12/1987       125000  MATHEWS         49
37836430        8/12/1987       62500   MATHEWS         49
37836449        8/12/1987       75000   MATHEWS         49
37836475        8/12/1987       125000  MATHEWS         49
37836474        8/12/1987       125000  MATHEWS         49
37836457        8/12/1987       200000  MATHEWS         89
37836466        8/12/1987       125000  MATHEWS         65
37836451        8/12/1987       125000  MATHEWS         65
37836512        8/12/1987       125000  MATHEWS         65
37836491        8/12/1987       100000  MATHEWS         49
37836514        7/20/1989       125000  SONIA   65
37836498        7/20/1989       125000  SONIA   49
37836500        7/20/1989       125000  SONIA   49
37836509        7/20/1989       250000  SONIA   49
37836472        7/20/1989       500000  SONIA   65
37836481        7/20/1989       62500   SONIA   65
37836450        7/20/1989       125000  SONIA   65

Code:
$awk 'NR==FNR{n[$4]+=$3;next} n[$4]>=3000000{print}' infile infile

O/P
Code:
37836452        1/13/1961       125000  ASHUTOSH        65
37836505        1/13/1961       500000  ASHUTOSH        49
37836455        1/13/1961       100000  ASHUTOSH        65
37836488        1/13/1961       250000  ASHUTOSH        75
37836473        1/13/1961       125000  ASHUTOSH        49
37836478        1/13/1961       250000  ASHUTOSH        49
37836519        1/13/1961       150000  ASHUTOSH        49
37836437        1/13/1961       500000  ASHUTOSH        49
37836461        1/13/1961       125000  ASHUTOSH        65
37836477        1/13/1961       250000  ASHUTOSH        65
37836486        1/13/1961       250000  ASHUTOSH        65
37836513        1/13/1961       500000  ASHUTOSH        65
37836431        1/13/1961       125000  ASHUTOSH        65

Please post your input file and code which you tried.
This User Gave Thanks to pravin27 For This Post:
# 12  
Old 07-21-2011
Bug

Thanks Pravin27,
Following is the code I have tried .bit changed from my original which is there in the first post.

Code:
#!/bin/sh
tput clear
tput cup 8 5 
echo -n 'Enter the Amt  file name:'
read c

awk -F: '{
       idx = $2 SUBSEP $4 
       arr[idx, ++arrCnt[idx]] = $0
      }
     END {
      for ( i in arrCnt)
      if ( arrCnt[i] > 1 )
      for ( c=1; c<=arrCnt[i]; c++)
      print arr[i,c],TDA[nam]
      }' n2 | sort -t: +3 -4d> n3  

awk -F: '{
          pol[nam]=$1
          dob[nam]=$2
          dab[nam]=$3
          nam=$4
          pln[nam]=$5
         TDA[nam]+=$3
          }
 END {
       for ( nam in TDA )
       if ( TDA[nam] >= '$c' )
     {
       printf"%8d:%30s \n",TDA[nam],nam
      }}' n3 |  sort -t: -n +1 -2d > n4 
 
awk -F"[:]" ' NR == FNR { a[$2]=$0;next} a[$4]{print}' n4 n3 > n5

Yes your code gave me out put , but it seems there may be some problem in the data , as in the dob format yyyy0601 is most common.

Anyway thanks once again for your kind guidence.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i do the vertical to horizontal??

51009 8746 8912 17986 20315 24998 5368 38934 7805 8566 (4 Replies)
Discussion started by: nikhil jain
4 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

3. UNIX for Dummies Questions & Answers

vertical to horizontal

dear all, i'm new to unix and i try to figure out the best case for making list of vertical text to become horizontal and skip the line 1 and 2. example text : Data DATE XXXXX MAX 47 53 49 51 48 48 7 46 51 8 25 (6 Replies)
Discussion started by: andrisetia
6 Replies

4. UNIX for Dummies Questions & Answers

Horizontal to vertical

Hi, Silly question, if I have an excel file that looks something like this: ................. Subject 1 Subject 2 Subject 3 Subject 4 Fever..............13...........9.............23..........14 Headache.........2............12...........18..........23... (3 Replies)
Discussion started by: Xterra
3 Replies

5. UNIX for Dummies Questions & Answers

vertical tabs

I am trying to get this to display vertically like in a table but it keeps jumping to a new line dev=$(df -h | grep ^/dev | cut -d " " -f1) dev1=$(df -h | grep ^/dev | cut -f 2 -d "%") dev2=$(df -h | grep ^/dev | cut -f 14-16 -d " ") dev3=$(df -h | grep ^/dev | cut -f 18-20 -d " ")... (1 Reply)
Discussion started by: gjanisse
1 Replies

6. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

7. UNIX for Dummies Questions & Answers

grep running total/ final total across multiple files

Ok, another fun hiccup in my UNIX learning curve. I am trying to count the number of occurrences of an IP address across multiple files named example.hits. I can extract the number of occurrences from the files individually but when you use grep -c with multiple files you get the output similar to... (5 Replies)
Discussion started by: MrAd
5 Replies

8. HP-UX

Easy one : command listing total memory

Hi, I have been searching for a command that lists the total amount of memory in the HP-UX doc but haven't found it yet. vmstat is not exactly what i want. Does the command exists on HP UX? :confused: :confused: :confused: :confused: :confused: (4 Replies)
Discussion started by: beginer
4 Replies

9. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question