LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2007, 09:48 AM   #1
tteklem
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Rep: Reputation: 0
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
 
Old 11-18-2007, 12:43 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 11-18-2007, 09:09 PM   #3
tteklem
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Tink that seem to be working

tteklem
 
Old 11-18-2007, 10:10 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

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



Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk help please stefaandk Programming 6 10-02-2007 08:50 AM
Awk opensource82 Linux - General 5 09-19-2007 10:08 AM
awk kalyanofb Programming 4 02-19-2007 02:55 AM
Do you know awk? Vitalka Programming 5 12-01-2006 11:42 PM
using awk wedgeworth Linux - Newbie 9 02-20-2004 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration