On Thu, 2007-11-15 at 14:25 -0800, Mark Knecht wrote:
> Hi,
>    I know this is EXTREMELY off topic but I don't know of another
> better list to ask on. I'm hoping maybe there is a Linux command line
> method for doing this. Thanks in advance.
> 
>    I have a data file with data that changes infrequently. The file
> lists only the day the data changes. There are only 144 lines
> representing 23 years of data. There are three values for the data -
> 1, 0 & -1. The file looks like this:
> 
> 09/27/74,   1
> 07/11/75,   -1
> 08/01/75,   1
> 03/12/76,   -1
> 04/02/76,   1
> 05/07/76,   -1
> 06/04/76,   1
> 
>    I need to turn this data into a file with the same format but one
> that has data for every date, something like this:
> 
> 09/28/74,   1
> 09/29/74,   1
> 09/30/74,   1
> ...
> ...
> ...
> 07/09/75,   1
> 07/10/75,   1
> 07/11/75,   -1
> 
> and so on...
> 
>    Would anyone proficient in Linux command line know how to do that?
> Or might there be some app in portage that could do this as part of
> it's functionality?
> 

You're probably not going to find something so specific "off the
shelf" (although if I'm wrong, someone will correct me).  Likely you'll
have to do some kind of scripting (either in bash or whatever). With
that in mind, it would be relatively easy to do in python:

Read the file and put data into a dict: 

>>> date_dict[datetime.date(1975, 04, 12)] = -1
...
Then write a loop
>>> start_date = datetime.date(1972, 3, 1)
>>> end_date = datetime.date(2007, .....
>>> one_day = datetime.datedelta(days=1)
>>> default_value = 1
>>> mydate = start_date
>>> while mydate <= end_date:
>>> ... value = date_dict.get(mydate, default_value)
>>> ... outfile.write('%s %s\n' % (mydate, value))
>>> ... mydate = mydate + one_day

That's the general idea, though the above code is incomplete and
untested.

BTW, 2-digit year is a bad idea (unless it's truly 74 AD ;-).

--
Albert W. Hopkins

-- 
[EMAIL PROTECTED] mailing list

Reply via email to