How to calculate average of csv using shell scripting?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to calculate average of csv using shell scripting?
# 1  
Old 01-13-2016
How to calculate average of csv using shell scripting?

Hi,
I need to calculate the average of the following values using shell scripitng.
Can anyone please suggest a solution?



Code:
Date,Time,nl45.1,nl45.2,nl45.3,nl45.4,nl46.1,nl46.2,nl46.3,nl46.4,nl46.5,nl47.1,nl47.2,nl47.3,nl47.4,nl47.5,nl48.1,nl48.2,nl48.3,nl48.4,nl49.1,nl49.2,nl49.3,nl50.1,nl50.2,nl50.3,nl50.4,nl50.5
12-01-2016,00:00,1,1,1,0,,0,1,1,0,0,0,0,1,3,1,1,0,0,0,,0,0,0,,,1,1,0,6,0,
12-01-2016,00:10,1,0,0,0,,2,1,1,1,0,0,0,0,1,1,1,0,0,0,,0,0,1,,,0,0,0,1,0,
12-01-2016,00:20,0,0,1,0,,0,0,0,0,0,0,0,1,0,0,1,0,0,0,,0,0,0,,,2,0,0,0,0,
12-01-2016,00:30,0,0,0,0,,1,0,0,1,0,0,2,2,0,0,0,0,0,0,,0,1,1,,,0,0,0,0,0,
12-01-2016,00:40,0,0,1,0,,1,0,1,0,0,0,0,0,1,1,0,0,0,0,,0,2,0,,,0,0,0,0,1,
12-01-2016,00:50,0,0,0,0,,0,0,1,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,,,1,0,0,1,1,
12-01-2016,01:00,0,1,0,0,,0,0,0,0,0,0,0,0,0,0,0,1,0,0,,0,0,2,,,1,0,0,1,0,
12-01-2016,01:10,0,0,0,0,,2,0,0,0,0,2,0,0,0,0,2,0,0,1,,1,0,0,,,0,0,0,0,1,
12-01-2016,01:20,0,0,0,0,,1,0,0,2,0,2,0,1,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,0,
12-01-2016,01:30,0,0,0,0,,1,1,0,1,0,0,0,0,0,1,0,0,0,1,,0,0,0,,,0,2,1,1,0,
12-01-2016,01:40,0,0,0,0,,1,1,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,,,1,0,0,0,1,
12-01-2016,01:50,0,0,1,0,,1,0,0,0,0,1,1,1,0,0,0,1,0,0,,1,1,1,,,0,0,0,0,0,
12-01-2016,02:00,0,0,0,0,,1,0,0,0,0,0,0,0,0,0,0,1,0,0,,0,0,0,,,0,0,0,1,1,


Last edited by Don Cragun; 01-13-2016 at 05:37 AM.. Reason: Add CODE tags.
# 2  
Old 01-13-2016
Hello and welcome to the forum.
Please use code tags for code blocks, as you have accepted by the forum rules.

Since this post is similar (if not identical) to
If this is a homework, please refer to the homework section of the forum and follow the guidelines that apply there.

Either way, any attempts from your side yet?
# 3  
Old 01-13-2016
In addition to what sea has already said, you need to provide a much clearer description of what you are trying to do. Are you looking for a single number that is the average value of the values all non-time, non-asterisk, non-empty, non-header fields? Are you looking for the average of values in each line? Are you looking for the average of values in each column? Are empty fields to be treated as zero and included in the average(s) or skipped?

At the very least, show us the output you hope to produce (in CODE tags) from the sample input you provided.
# 4  
Old 01-13-2016
Hi,
What I want here is the calculation of column wise average, and then average for each row accordingly, and there should not be any empty columns in between.
For example:-
Code:
Date	Time	nl45.eu1	nl45.eu2	nl49.eu1	nl49.eu2	nl13.eu1
12/1/2016	0:00	1066	1089	1092	1123	1092.5
12/1/2016	0:10	1029	985	1067	1068	1037.25
12/1/2016	0:20	1008	974	1018	1085	1021.25
12/1/2016	0:30	1097	1051	1111	1136	1098.75
12/1/2016	0:40	1199	1189	1226	1244	1214.5
12/1/2016	0:50	1176	1182	1197	1229	1196
12/1/2016	1:00	1069	1092	1421	1149	1182.75
12/1/2016	1:10	1140	1091	1445	1138	1203.5
12/1/2016	1:20	1089	1013	1211	1076	1097.25
12/1/2016	1:30	909	819	943	941	903
						1104.675

Please let me know if this is still not clear

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags for code, file data and terminal output. Thank you.

Last edited by bakunin; 01-13-2016 at 06:26 AM..
# 5  
Old 01-13-2016
I can't see any relation between the data in post#1 and those in post#4, neither in header nor in the data themselves. And, no effort from your side can be seen...
# 6  
Old 01-13-2016
Quote:
Originally Posted by RudiC
I can't see any relation between the data in post#1 and those in post#4, neither in header nor in the data themselves. And, no effort from your side can be seen...
Amen! I can only emphasize this. On top, there is a tutorial explaining exactly how you can do what you seemingly want to do yourself:
How to do a "Control Break" (Algorithm)

I hope this helps.

bakunin
# 7  
Old 01-13-2016
Hi,
Yes,I have posted a different file here.But. the purpose is same. I am not much familiar with UNIX,so, I don't know where to proceed from.
Could you please help me with this its really urgent.
If there is a confusion between the two data's consider the second one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reconciling two CSV files using shell scripting

I have two CSV files file1, file2 as below File 1: Key, Value1, Value2, Value3, Value4,......value A,50,100,50,40,....,100 File 2: Key, value1,Value2,Value3,Value 4 so on... A,50,80,45,50..... Now, I want to check if key from file 1 is present in file 2 or not if present I want to... (9 Replies)
Discussion started by: hustler
9 Replies

2. Shell Programming and Scripting

Calculate the average per block.

My old school way is a one liner. And will search for average from SAR, to get the data receive rate. But, I dont think it is practical or accurate,. Because it calculates to off peak hours. I am planning to change it. My cron runs every 30 mins. When my cron runs, and my time is 14:47pm,, it will... (1 Reply)
Discussion started by: invinzin21
1 Replies

3. Shell Programming and Scripting

How to calculate avg values of csv file using shell scripting .?

hi all i have a reporting work and i want it to be automated using shell scripting kindly let me know how can i make that possibe . eg data are :... (2 Replies)
Discussion started by: Avinash shaw
2 Replies

4. 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

5. Shell Programming and Scripting

Shell scripting:from text file to CSV

Hello friends, I have a file as follows: "empty line" content1 content2 content3 content1 content2 content3 content1 content2 content3 It starts with an empty line, how can i get a csv like this: (12 Replies)
Discussion started by: kraterions
12 Replies

6. Shell Programming and Scripting

Calculate average from CSV file using PERL script

Hi All I have this csv file and I need to calculate the average of FPS. FPS:27.7420, Interval:1314184238772 FPS:25.9798, Interval:1314184242646 FPS:27.4772, Interval:1314184246311 FPS:26.1623, Interval:1314184250159 FPS:26.4515, Interval:1314184253972 FPS:31.5896, Interval:1314184257163... (24 Replies)
Discussion started by: sayachop
24 Replies

7. Shell Programming and Scripting

How to calculate months and display in shell scripting

I just want to know, how do we calculate the months in shell scripting. If i give the input as 20-01-2011, the output should be 20-02-2011, 20-03-2011 or 20-04-2011........ How do i get this ? Cheers. (6 Replies)
Discussion started by: sachin24
6 Replies

8. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

9. Programming

calculate average

I have a file which is 2 3 4 5 6 6 so i am writing program in C to calculate mean.. #include<stdio.h> #include<string.h> #include <math.h> double CALL mean(int n , double x) main (int argc, char **argv) { char Buf,SEQ; int i; double result = 0; FILE *fp; (3 Replies)
Discussion started by: cdfd123
3 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