Average in awk based on time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Average in awk based on time
# 8  
Old 07-30-2008
Sorry I don't know much about awk , but I still got error as below:
Code:
awk: hr_2_davg.awk:3: awk -F, '
awk: hr_2_davg.awk:3:         ^ invalid char ''' in expression

Thank you so much for help!

Last edited by Don Cragun; 04-17-2016 at 12:34 AM.. Reason: Add CODE tags.
# 9  
Old 07-30-2008
seems there is a type in frankilins reply

Code:
awk -F, '
  $4>0{
    split($2,s," ")
    sub("\"","",s[1])
    e=s[1]
    a[e]+=$4
    b[e]++
  }
END{
  for(i in a){
    print "Average for " i " = " a[i]/b[i]
  }
}' file


Last edited by Don Cragun; 04-17-2016 at 12:35 AM.. Reason: Add CODE tags.
# 10  
Old 07-31-2008
I'm very sorry, jayapal is right, another typo, I had an off day, this is tested and should work:
Code:
awk -F, '
  $4>0{
    split($2,s," ")
    sub("\"","",s[1])
    e=s[1]
    a[e]+=$4
    b[e]++
  }
END{
  for(i in a){
    print "Average for " i " = " a[i]/b[i]
  }
}' file

Regards
# 11  
Old 07-31-2008
still get error

Everything looks fine to me now, but I keep getting error message as below:

Code:
awk: ./hr_2_davg.awk:3: awk -F, '
awk: ./hr_2_davg.awk:3:         ^ invalid char ''' in expression

Thank you very much.

Last edited by Don Cragun; 04-17-2016 at 12:36 AM.. Reason: Add CODE tags.
# 12  
Old 07-31-2008
Have you tried nawk or gawk? On Solaris use /usr/xpg4/bin/awk.
# 13  
Old 07-31-2008
I tried awk and gawk

Thank you for your time, Franklin52. I am using linux here. I had tried everything I can think of with both awk and gawk (we don't have nawk). But still get same error. Did I miss sth?
# 14  
Old 07-31-2008
It works fine for me, do you have a typo anywhere? Copy the code, save it in file and make it executable with chmod and run it as a regular script. Don't forget to adapt the filename.

Code:
#!/bin/sh

awk -F, '
  $4>0{
    split($2,s," ")
    sub("\"","",s[1])
    e=s[1]
    a[e]+=$4
    b[e]++
  }
END{
  for(i in a){
    print "Average for " i " = " a[i]/b[i]
  }
}' file

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Average columns based on header name

Hi Friends, I have files with columns like this. This sample input below is partial. Please check below for main file link. Each file will have only two rows. ... (8 Replies)
Discussion started by: jacobs.smith
8 Replies

2. Shell Programming and Scripting

Awk: time intervals based on epoch time

I have a list of epoch times delimited by "-" as follows: 1335078000 - 1335176700 1335340800 - 1335527400 1335771300 - 1335945600 1336201200 - 1336218000 The corresponding dates are: 20120422 1000 - 20120423 1325 20120425 1100 - 20120427 1450 20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies

3. Shell Programming and Scripting

KSH or AWK for fetching the first and the last line based on time.

Dears could anybody please help me with the below task as I am a newbie to programming. I have a text file with 4 columns (priv_ip,time,pub_ip). eg: 10.160.101.160,0708044510,22.203.195.151 10.160.101.160,0708044645,22.203.195.151 10.160.101.160,0708050410,22.203.195.151... (5 Replies)
Discussion started by: BrownBob
5 Replies

4. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

AWK: how to get average based on certain column

Hi, I'm new to shell programming, can anyone help me on this? I want to do following operations - 1. Average salary for each country 2. Total salary for each city and data that looks like - salary country city 10000 zzz BN 25000 zzz BN 30000 zzz BN 10000 yyy ZN 15000 yyy ZN ... (3 Replies)
Discussion started by: shell123
3 Replies

6. Shell Programming and Scripting

Average calculation based on number of rows

Dear users, I need your support, I have a file like this: 272134.548 6680572.715 272134.545 6680572.711 272134.546 6680572.713 272134.548 6680572.706 272134.545 6680572.721 272134.543 6680572.710 272134.544 6680572.715 272134.543 6680572.705 272134.540 6680572.720 272134.544... (10 Replies)
Discussion started by: Gery
10 Replies

7. Shell Programming and Scripting

calculate the average of time series data using AWK

Hi, I have two time series data (below) merged into a file. t1 and t2 are in unit of second I want to calculate the average of V1 every second and count how many times "1" in V2 is occur within a second Input File: t1 V1 t2 V2 10.000000... (5 Replies)
Discussion started by: nica
5 Replies

8. Shell Programming and Scripting

Remove lines, Sorted with Time based columns using AWK & SORT

Hi having a file as follows MediaErr.log 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:12:16 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:22:47 84 Server1 Policy1 Schedule1 master1 05/08/2008 03:41:26 84 Server1 Policy1 ... (1 Reply)
Discussion started by: karthikn7974
1 Replies

9. UNIX for Dummies Questions & Answers

Average Time

Hi Guys, I am using a command $ runprt_req PPGUS_ROYXN1102 Output: **************** Start Date and Time End Date and Time*** PPGUS_ROYXN1102 01/15/2008 02:20:08 01/15/2008 04:54:50 PPGUS_ROYXN1102 01/12/2008 02:03:57 01/12/2008 04:22:10... (1 Reply)
Discussion started by: sambond
1 Replies

10. Shell Programming and Scripting

average transaction time

Hi all, I have large daily log file(s) that hold the times for requests and responses on different system requests. What I want to do is work out average transaction times for the day (one log = one day). The problem I'm having is figuring out how to skip rows, i've sorted the output by uniq... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question