Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi

I have a file with this fields:

date, subscriber a, suscriber b, country b, date, seconds.

and I want to obtain this resume:

date, subscriber a, country b, total calls, total seconds, quantity subcriber b differents

my initial program


t[date";"subscriber a"," suscriber b"," country b]++
d[date";"subscriber a"," suscriber b"," country b]+=$seconds

for ( i in t )
print i","t","d

but this report print subcriber b. I want to print only quantity of call to diffents subscribers b.

desired output:

subscriber A, country A, 10 calls , 20 seconds, quantity of diferents subcribers B( example 10 differents subscribers B)


Thanks

malpa


 

Hi

excusme

desired output:

date, subscriber A, country B, 10 calls , 20 seconds, quantity of diferents subcribers B( example 10 differents subscribers B)

thanks malpa
 

Hi

This is my solution, but I would like to know if there is another posibility.

BEGIN{FS=","}
NR>1{
date=$1
a=$2
b=$3
country=$4
duration=$5

z[date";"a";"country]=z[date";"a";"country]"|"b
t[date";"a";"country]+=duration
}
END{
for ( p in z) {
split(z[p],array_k,"|")
n=asort(array_k)
for ( j = 2; j<=n; j++ ) {
# printf "%s ",array_k[j];
h[array_k[j]]++
}
#print "\n"
l=asort(h)
#print l
#for ( r in h ) printf r";"h[r]
#print "\n"
print p";"l";"t[p]
delete h


}
}

input.txt
date, a, b, country,seconds
1,a,b,A,2
1,a,b,A,3
1,a,c,A,3
1,a,j,A,1
1,a,e,B,2
1,b,d,A,4
2,a,b,A,1
2,a,d,A,4


output.txt
date,a,country,total calls, total seconds
1;b;A;1;4
2;a;A;2;5
1;a;A;3;9
1;a;B;1;2

thanks malpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top