LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk help (https://www.linuxquestions.org/questions/linux-newbie-8/awk-help-600570/)

tteklem 11-18-2007 08:48 AM

awk help
 
I have a large annual data with a time stamps that increment by 0.002 minutes (ie 1.002 ...365.998 ). Some data is missing in the data and the time stamp is not regularly spaced (e.g 1.002, 1.006 skipping 1.004). the desired output is 1st generate artificial data in column 1 as a time stamp 1.00 to 365.998 regularly spaced with a step of 0.002. Then sort my data to this column puting the data stamp but leaving the values empty when data is missing so that my time series data is equally spaced with empty lines when data point is missing. I have the following awk code to do the job but this will only count by 1.


awk '{a[$1]=$0}END{for(i=1;i<=366;++i) print ((i in a)?a[i]:i)}' /path/to/input

I am not sure how to make it count by 0.002 instead. I am new to awk and appreciate any tips!

Thanks

Tinkster 11-18-2007 11:43 AM

Hi,

And welcome to LQ!


Does this help?

Code:

i=1
while(i<366000){
  print ((i/1000 in a)?a[i/1000]:i/1000)
  i+=2
}


Cheers,
Tink

tteklem 11-18-2007 08:09 PM

Thanks Tink that seem to be working

tteklem

Tinkster 11-18-2007 09:10 PM

Sweet :}

It's a bit of a kludge, but awks for loop has no notion of a step.

It may run faster if you evaluate the quotient once, assign it to a variable
and then use that... only just noticed how ugly my hack was :D

Code:

i=1
while(i<366000){
  j=i/1000
  print ((j in a)?a[j]:j)
  i+=2
}




Cheers,
Tink


All times are GMT -5. The time now is 11:08 PM.