Vertical total and listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vertical total and listing
# 1  
Old 07-16-2011
Vertical total and listing

file 1
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

My code is:
Code:
#!/bin/sh
tput clear
tput cup 8 5 
echo -n 'Enter the Minimum Amt  :'
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: '{
          vou[nam]=$1
          dob[nam]=$2
          amt[nam]=$3
          nam=$4
          typ[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[$4]=$0;next} a[$4] {print $0}' n4 n3 > n5

Working on LINUX OS.
In my data file it is : seperated .
What I want is, if the amount is , equal to or greater than given amount, then
it should list all the entris of the said person with all the details.With my code I am not getting the desired out put, that is the not only sum total but
along with the voucher number.
With the last line I tried but there is some mistake ?
Can any one help ??
Thanks in advance .

Last edited by Franklin52; 07-17-2011 at 06:33 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-16-2011
You have about 60+ posts but still you are not using code tags. Can you please edit your post and add
Code:
code tags

?
This User Gave Thanks to matrixmadhan For This Post:
# 3  
Old 07-16-2011
Should the separator be space instead in your awk code?
Code:
awk -F" "

# 4  
Old 07-17-2011
Quote:
Originally Posted by jostber
Should the separator be space instead in your awk code?
Code:
awk -F" "


A single space is the default delimiter in awk
# 5  
Old 07-17-2011
vertical total

with due apology ,matrixmadhan, for the inconvenience here it is in code tag .
Code:
My code is:
#!/bin/sh
tput clear
tput cup 8 5 
echo -n 'Enter the Minimum Amt :'
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: '{
vou[nam]=$1
dob[nam]=$2
amt[nam]=$3
nam=$4
typ[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[$4]=$0;next} a[$4] {print $0}' n4 n3 > n5

The filed seperator in the original data file is : , Anyway if , say the data required is for Amount more than 3000000 the result expected is as below :

CHA 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 3250000

It should give full details of data.
# 6  
Old 07-17-2011
vakharia Mahesh no apologies please, you have not committed any sin. Just try to use CODE tags when necessary.
# 7  
Old 07-18-2011
How about this,
Code:
awk '$3>=3000000{print;a+=$3} END {print "Total Amount: " a} ' infile

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