LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-12-2014, 11:15 AM   #1
mfarch99
LQ Newbie
 
Registered: Mar 2012
Posts: 20

Rep: Reputation: Disabled
Lightbulb create file with Julian date and current time --- then subtract 5 minutes


I need to create a one record file that contains information that looks similar to the one below. The record will always contain the number 70 in columns 1 and 2. The other entries are the date and time both to and from in the format of yyddd(ddd is Julian) and time in hhmm.

Once this file is created I will need to continue to create new files that have the time increase by 5 minutes. If the date changes that will need to change as well. The format of the file needs to look like this:
position 1 and 2 -- 70, positions 11-15 current date in yyddd format, positions 16-19 current time in format hhmm, positions 20-24 to date in yyddd format and positions 25-28 increment of 5 minutes in hhmm format. Here is an example of the entry:

70 141630800141630805

Any assistance would be appreciated...
 
Old 06-12-2014, 11:22 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
And what do you have so far, and what is it written in?
 
Old 06-12-2014, 11:32 AM   #3
mfarch99
LQ Newbie
 
Registered: Mar 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
I have nothing at this point generated. I was thinking using bash..
 
Old 06-12-2014, 11:33 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
That's ordinal date, not julian date:
http://en.wikipedia.org/wiki/Ordinal_date
http://en.wikipedia.org/wiki/Julian_day

As somebody who uses julian date (and modified julian date) every day, it really bothers me when somebody calls ordinal date/day of year "julian"...

[/soapbox]

If this is bash, you can use date to spit out that date string, and you can use the "-d" flag to tell it what time to use, including "+5 minutes" to get the time 5 minutes in the future.

Last edited by suicidaleggroll; 06-12-2014 at 11:38 AM.
 
2 members found this post helpful.
Old 06-12-2014, 11:51 AM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Someone should talk to the maintainers of the 'date' program then, since the number of days since the beginning of the year is %j instead of %o. That is probably contributing to the misnomer.

edit: I sent an email to the coreutils maintainers at gnu.org pointing it out. Perhaps something will be done about it. Probably not though, since it will break scripts left and right. But perhaps a note in the manual page would be nice.

The OP is looking for an example or some code,.. using the 'date' program, and the horribly named %j parameter, we could do something like:

Code:
TMP=`date +%y%j%H%m%y%j%H%m`
while true; do
 echo 70 70 $TMP
 let TMP=TMP+5
done

Last edited by szboardstretcher; 06-12-2014 at 11:57 AM.
 
1 members found this post helpful.
Old 06-12-2014, 02:27 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Something like this, perhaps?
Code:
#!/bin/bash

Now=$(date +%s)
Current=$(date -d @$Now +%y%j%H%M)
Limit=$((Now+100*24*3600))  # Set limit to 100 days -- adjust as needed

while [ $Now -lt $Limit ]
do  Now=$((Now+5*60))       # 5  minute increment
    date -d @$Now "+70        ${Current}%y%j%H%M"
done
You'll need to round $Now to a multiple of 300 (5 minutes) if you want the output minutes to be multiples of 5. That part is left as an exercise.
 
1 members found this post helpful.
Old 06-12-2014, 02:31 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Got a reply from gnu.org about the Julian-ish named %j variable in 'date'

Quote:
Please read the discussion at
https://lists.gnu.org/archive/html/c.../msg00019.html

There are two different definitions for Julian date. POSIX has
standardized %j to mean the count of days within a Gregorian year, and
NOT the astronomical Julian date.
http://pubs.opengroup.org/onlinepubs/9699919799/toc.htm

We are reluctant to burn %o without it being required by POSIX, because
strftime letters are already sparse; this is particularly true of
burning a letter to be a synonym to an already standardized letter. The
proposal in the thread mentioned above would be to add a %J as the
Astronomical Julian date, if there proves to be enough demand, but so
far, no one has expressed enough interest to actually write the patch.

Therefore, I'm closing this as not a bug, although you can feel free to
add further replies to the thread.
Of course, the argument against it is tight as well. The wikipedia article suicidaleggroll references straight up says that outside of Astronomy/historical context, ie computers, that Julian date means exactly what was proposed at the beginning of this thread.

Quote:
Outside of an astronomical or historical context, if a given "Julian date" is "40", this most likely means the fortieth day of a given Gregorian year, namely February 9.

Last edited by szboardstretcher; 06-12-2014 at 02:41 PM.
 
1 members found this post helpful.
Old 06-12-2014, 03:07 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by szboardstretcher View Post
The wikipedia article suicidaleggroll references straight up says that outside of Astronomy/historical context, ie computers, that Julian date means exactly what was proposed at the beginning of this thread.
Just because some people use it in that fashion doesn't mean it's correct

A lot of people use the phrase "I could care less" when they are trying to say they don't care about something. It doesn't mean that's the correct saying.

Last edited by suicidaleggroll; 06-12-2014 at 03:08 PM.
 
Old 06-12-2014, 03:33 PM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Agreed.

Though on that note, it might not be correct right now, but as time passes it will become accepted just as many, many phrases and words do.
 
Old 06-12-2014, 06:45 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I wonder that the US Military's definition of "Julian Date" is. They use it, or I've seen it in some accompanying documentation on the contracts I saw at General-Atomics for the Predator Aircraft.
 
Old 06-18-2014, 08:07 AM   #11
mfarch99
LQ Newbie
 
Registered: Mar 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Thank you. I will take a look at the above and see if these will assist in what I have been working on. I will post the resolution when complete.

Thank you for the date explanation also.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Convert Julian date to Calendar date keif Programming 3 03-21-2014 09:16 AM
PHP: formatting current date & time as: 2006-04-12 13:47:36 and substract 15 minutes NaCo Linux - Software 4 11-13-2008 07:31 PM
Appending current date and time to a file frankietomatoes Linux - General 5 11-18-2002 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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