Help with calculate statistics between two column info


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with calculate statistics between two column info
# 1  
Old 10-25-2012
Help with calculate statistics between two column info

Input file
Code:
1159,310,       159797120,159817366,    
142,199,218,91, 26551038,26551729,26552411,26552894,    
91,273,349,     26481990,26482133,26482477,

Desired output result
Code:
19087
549	483	265
52	71

I have long list of input file as shown above.
I would like to use the info at second column minus first column to get the distance result.
The theory behind to manual calculate to get the Desired output result
Code:
159817366-159797120-1159=19087
26551729-26551038-142=549	26552411-26551729-199=483	26552894-26552411-218=265
26482133-26481990-91=52	26482477-26482133-273=71

As shown above, 19087 is calculated by 159817366(second info at column two)-159797120(first info at column two)-1159(first info at column one).
All the input file, column 2 sure have at least two info.
The theory to get the each number is calculated by use the front record (second info) in column two minus the back record (first info) in column two and first record (first info) in column one, and so forth

Thanks for any advice.
# 2  
Old 10-25-2012
Code:
awk '{split($1,P,",");n=split($2,Q,",");for(i=1;i<=(n-2);i++){printf Q[i+1]-Q[i]-P[i] " "}print ""}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 10-25-2012
Code:
awk '{split($1,c1,",")
no_of_c2=split($2,c2,",")
for(i=2;i<no_of_c2;i++)
 printf "%d\t", c2[i]-c2[i-1]-c1[i-1]
printf "\n"
}' file

Or with perl:
Code:
perl -ane '@c1=split /,/,$F[0];
@c2=split /,/,$F[1];
for($i=1;$i<@c2;$i++) {printf "%d\t",$c2[$i]-$c2[$i-1]-$c1[$i-1]}
print "\n"' file


Last edited by elixir_sinari; 10-25-2012 at 06:53 AM..
This User Gave Thanks to elixir_sinari For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with calculate the total sum of record in column one

Input file: 101M 10M10D20M1I70M 10M10D39M4I48M 10M10D91M 10M10I13M2I7M1I58M 10M10I15M1D66M Output file: 101M 101 0 0 10M10D20M1I70M 100 1 10 10M10D39M4I48M 97 4 10 10M10D91M 101 0 10 10M10I13M2I7M1I58M 88 13 0 10M10I15M1D66M 91 10 1 I'm interested to count how many total of... (6 Replies)
Discussion started by: perl_beginner
6 Replies

2. Shell Programming and Scripting

Calculate 5th percentile based on another column

I would like to have some help in calculating 5th percentile value of column 2 for each site, the input is like below:site val1 val2 002 10 25.3 002 20 25.3 002 30 25.3 002 40 20 002 50 20 002 60 20 002 70 20 002 80 30 002 90 30 002 100 30 002 120 30 003 20 30.3 003 20 30.3 003 30 20... (2 Replies)
Discussion started by: wuhuai
2 Replies

3. Shell Programming and Scripting

Calculate Average time of one column

Hello dears, I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST ... (2 Replies)
Discussion started by: Newman
2 Replies

4. Shell Programming and Scripting

Calculate the average of a column based on the value of another column

Hi, I would like to calculate the average of column 'y' based on the value of column 'pos'. For example, here is file1 id pos y c 11 1 220 aa 11 4333 207 f 11 5333 112 ee 11 11116 305 e 11 11117 310 r 11 22228 781 gg 11 ... (2 Replies)
Discussion started by: jackken007
2 Replies

5. Shell Programming and Scripting

Calculate 2nd Column Based on 1st Column

Dear All, I have input file like this. input.txt CE2_12-15 3950.00 589221.0 9849709.0 768.0 CE2_12_2012 CE2_12-15 3949.00 589199.0 9849721.0 768.0 CE2_12_2012 CE2_12-15 3948.00 589178.0 9849734.0 768.0 CE2_12_2012 CE2_12-52 1157.00 ... (3 Replies)
Discussion started by: attila
3 Replies

6. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

7. Shell Programming and Scripting

Help with total up all column info

Input file 11916 30640 9320 51876 5690 15874 4723 26287 5121 12269 2569 19959 9 71 6 86 Desired output file 11916 30640 9320 51876 5690 15874 4723 26287 5121 12269 2569 19959 9 71 6 86 22736 58854 16618 98208 Last part is the total up of first three data. I used the following... (6 Replies)
Discussion started by: perl_beginner
6 Replies

8. Shell Programming and Scripting

How to calculate the percentage for the values in column

Hi, I am having the file which contains the following two columns. 518 _factorial 256 _main 73 _atol 52 ___do_global_ctors 170 ___main 52 ___do_g How can calculate the percentage of each value in the first column ? first need to get the sum of the first column and... (3 Replies)
Discussion started by: saleru_raja
3 Replies

9. UNIX for Dummies Questions & Answers

Use awk to calculate average of column 3

Suppose I have 500 files in a directory and I need to Use awk to calculate average of column 3 for each of the file, how would I do that? (6 Replies)
Discussion started by: grossgermany
6 Replies

10. UNIX for Dummies Questions & Answers

calculate average of column 2

Hi I have fakebook.csv as following: F1(current date) F2(popularity) F3(name of book) F4(release date of book) 2006-06-21,6860,"Harry Potter",2006-12-31 2006-06-22,,"Harry Potter",2006-12-31 2006-06-23,7120,"Harry Potter",2006-12-31 2006-06-24,,"Harry Potter",2006-12-31... (0 Replies)
Discussion started by: onthetopo
0 Replies
Login or Register to Ask a Question