Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complete missing lines 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
hello,

The collection file contains (example):

--cut--
2008-02-01 12:36:00 s2 32.6837225274725
2008-02-01 12:46:00 s2 32.6837225274725
2008-02-01 13:01:01 s2 32.7008928571429
--cut--

For a month measure (2008-02) I need to complete missing measures with "n/a". The measures are done every 5 minutes (seconds in example should be ignored).

In the other words, after processing above example I would expect following result:

2008-02-01 12:36:00 s2 32.6837225274725
2008-02-01 12:41:00 s2 n/a
2008-02-01 12:46:00 s2 32.6837225274725
2008-02-01 12:51:00 s2 n/a
2008-02-01 12:56:00 s2 n/a
2008-02-01 13:01:01 s2 32.7008928571429


thank you very much in advance!
 
Hi

Code:
[blue]master #[/blue] awk '{n=mktime(gensub(/[-:]/," ","g",$1" "substr($2,1,6)"00"))}NR>1{while((l+=5*60)<n){print strftime("%F %T",l)"\ts2\tn/a"}}{l=n}1' <<EOD
[blue]>[/blue] 2008-02-01 12:36:00     s2        32.6837225274725
[blue]>[/blue] 2008-02-01 12:46:00     s2        32.6837225274725
[blue]>[/blue] 2008-02-01 13:01:01     s2        32.7008928571429
[blue]>[/blue] EOD
2008-02-01 12:36:00     s2        32.6837225274725
2008-02-01 12:41:00     s2      n/a
2008-02-01 12:46:00     s2        32.6837225274725
2008-02-01 12:51:00     s2      n/a
2008-02-01 12:56:00     s2      n/a
2008-02-01 13:01:01     s2        32.7008928571429
Notes :
[ol]
[li]I do not understand the "measure" part. So my code reproduces the sample output by filling gaps walking between the start and end records.[/li]
[li]The above will only work with [tt]gawk[/tt].[/li]
[li]geirendre is right...[/li]
[/ol]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top