Sponsored Content
Top Forums Shell Programming and Scripting AWK - phone bill with several files Post 302524409 by chihung on Monday 23rd of May 2011 08:56:29 AM
Old 05-23-2011
kumaran_5555 missed out the 2nd argument 'file1.txt'
Code:
awk 'FNR==NR{tarif[$1]=$2;next}{cust[$1] += ($2 * tarif[$3])} END{ for (i in cust) print i,cust[i]}' file2.txt file1.txt
666666661 53.98
666666662 56.1
666666663 10.71
666666664 44.46
666666665 131.04

This may be a lot easier for Godie to understand
Code:
awk '

# process first file (file2.txt) to build up the lookup table
NR==FNR {
	tarif[$1]=$2
	next
}

# process all the records in the second file (file1.txt)
{
	cust[$1] += $2 * tarif[$3]
}

# output the total per phone number 
END{
	for ( i in cust ) {
		print i, cust[i]
	}
}' file2.txt file1.txt

This User Gave Thanks to chihung For This Post:
 

We Also Found This Discussion For You

1. Solaris

Solaris View/Transfer Files Android Phone

I'm trying to sync/transfer files from my UNIX box and Android Phone and vice versa. I know that Android Phones show up seamlessly (mostly) in Linux given their incestuous relationship. Is there a way to do it in UNIX or more specifically in Solaris 11.3 (i86)?:confused: I haven't found one... (2 Replies)
Discussion started by: Nostradamus1973
2 Replies
All times are GMT -4. The time now is 07:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy