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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find missing dates?

Status
Not open for further replies.

cuervo11

Programmer
Feb 11, 2015
1
Hello guys, I have a problem, I need find the missing dates of the year, for example this is my input:
2014-11-25T12:00:00
2014-11-26T12:00:00
2014-11-27T12:00:00
2014-11-28T12:00:00
2014-11-29T12:00:00
2014-11-30T12:00:00
2014-11-01T12:00:00
2014-11-02T12:00:00
2014-11-03T12:00:00
2014-11-04T12:00:00
2014-11-05T12:00:00
2014-11-06T12:00:00
2014-11-07T12:00:00
2014-11-08T12:00:00
2014-11-09T12:00:00
2014-11-10T12:00:00
2014-11-11T12:00:00

And the output will be all dates in that format less the dates I have, any ideas?

 
Hi

The easiest is to load all those data in an array, then loop from January 1[sup]st[/sup] to December 31[sup]st[/sup] and display those not in the array :
Code:
gawk 'd[teal][[/teal][navy]$1[/navy][teal]]=[/teal][purple]0[/purple][teal];[/teal][b]END[/b][teal]{[/teal][navy]t[/navy][teal]=[/teal][COLOR=FF6600]mktime[/color][teal]([/teal]year[i][green]" 01 01 12 00 00"[/green][/i][teal]);[/teal][b]while[/b][teal](([/teal][navy]s[/navy][teal]=[/teal][COLOR=FF6600]strftime[/color][teal]([/teal][i][green]"%FT%T"[/green][/i][teal],[/teal]t[teal]))&&[/teal][b]substr[/b][teal]([/teal]s[teal],[/teal][purple]1[/purple][teal],[/teal][purple]4[/purple][teal])==[/teal]year[teal]){[/teal][b]if[/b][teal](!([/teal]s [b]in[/b] d[teal]))[/teal][b]print[/b] s[teal];[/teal]t[teal]+=[/teal][purple]60[/purple][teal]*[/teal][purple]60[/purple][teal]*[/teal][purple]24[/purple][teal]}}[/teal]' year=2014 /path/to/input
The above code works with GNU [tt]awk[/tt] only. You have to specify the year as variable assignment in the command line and specify the input file name too.

Note that you may want to hard code the hour of day as 12 in case your machine's time zone supports daylight saving and you not want the noon at summer to be 13:00:00. ( I mean, just change "%T" to "12:00:00". )


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top