Summarize the values from files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Summarize the values from files
# 1  
Old 09-27-2012
Summarize the values from files

One of my process will create a file Market.txt with data like below.
Count Markt file
334936 /pdm/data001/P3_Quest_5HT_AMERGE.csv
2770787 /pdm/data001/P3_Quest_ARB_ATACAND.csv
1198143 /pdm/data001/P3_Quest_Bisp_ACTONEL.csv
3821864 /pdm/data001/P3_Quest_CONTRA_ALL_OTHER_CONTRA.csv
5014463 /pdm/data001/P3_Quest_Diab_ACTOSPLUS.csv

I will have another file Product.txt with data like below.
Marketname Products
5HT 13
ARB 11
Bisp 4
Contr 41
Diab 31
Now from first file market.txt i want to get the count of respective market and want to multiply with products which is Product.txt .Like that i want to get value from first file and want multiply with product for all markets and finally i want to summarize value for all the markets.
example
334936*13+2770787* 11+1198143* 4+3821864*41+5014463* 31=409560379929

Using shell script how to achive above one.

Note:In both files market names will be in same order.
# 2  
Old 09-27-2012
Is that sum value is right?

Code:
 awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{print sum}' Market.txt Product.txt

# 3  
Old 09-28-2012
i am getting result as 3.5177e+08.it is displaying wrong answer.
# 4  
Old 09-28-2012
Code:
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20f";print sum}' Market.txt Product.txt

# 5  
Old 09-28-2012
Its working ,Thanks for the Help but I am getting result as 351770174.000000 i want to display as 351770174.
# 6  
Old 09-28-2012
Code:
 
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt

# 7  
Old 09-28-2012
Or
Code:
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20d";print sum}' Market.txt Product.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace Stub Values In One Group Of Files With Actual Values From Another Group Of Files

I have two directories of files (new-config-files and old-config-files): new-config-files/this-db/config.inc.php new-config-files/that-db/config.inc.php new-config-files/old-db/config.inc.php new-config-files/new-db/config.inc.php new-config-files/random-database/config.inc.php etc. ... (4 Replies)
Discussion started by: spacegoose
4 Replies

2. Shell Programming and Scripting

Using awk to Summarize Log File in 5min Intervals

I have huge log file that taken every minute and I need the total at 5min intervals. Sample log: #timestamp(yyyymmddhhmm);result;transaction 201703280000;120;6 201703280001;120;3 201703280002;105;3 201703280003;105;5 201703280004;105;5 201703280005;105;4 201703280006;120;2... (2 Replies)
Discussion started by: wwolfking
2 Replies

3. Shell Programming and Scripting

Bash cript to calculate summarize address

Hi, I need to write a bash script that when i enter two ip address, it will calculate summerize address for them. Examlpe: 192.168.1.27/25 192.168.1.129/25 Result will be: 192.168.1.0/24 can you help me with this script? I even dont know how to start with it (3 Replies)
Discussion started by: Miron
3 Replies

4. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

5. Programming

Can someone summarize what exactly this perticular code is doing

#include<stdio.h> #include<string.h> int main() { char a={0,1,2,3,4,5,6,7,8,9}; printf("\n--%s-- unable to access values",a); printf("\n--%d %d-- able to access through direct acess",a,a); printf("\n--%d-- but the failing to read the size\n",strlen(a)); return 0; } (2 Replies)
Discussion started by: hk108
2 Replies

6. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

7. Shell Programming and Scripting

Summarize file with column matching

Guys, Please help me with this code. I have 2GB file to process and shell seems to be the best option. I am a biologist and though I can think of the logic, the commands are beyond me. Any help is greatly appreciated. Please look at the attched file and the requirement will be very clear. I... (6 Replies)
Discussion started by: newbie83
6 Replies

8. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

9. Shell Programming and Scripting

Summarize the sed script

Hi folks, I have a situation where i have a raw file like cat file_raw 776 713 111 0776713113 317-713-114 235776713115 776713116 336713117 77 6 713 118 0776713119 235776713120 and would like to replace all leading zeros with 235, remove all spaces and dashes, and make all... (3 Replies)
Discussion started by: jerkesler
3 Replies

10. Shell Programming and Scripting

sort and summarize

Hi Guys, I have a file in UNIX with duplicates, I have use sort command as below to delete duplicates based on the KEY positions/columns but now I do not want to "delete" duplicates but summarize by KEY numeric columns. REALLY NEED HELP... URGENT!!! Thanks in advance. sort -k 1.1,1.92... (6 Replies)
Discussion started by: shotronix
6 Replies
Login or Register to Ask a Question