Awk convert from day of year to date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk convert from day of year to date
# 1  
Old 07-17-2011
Awk convert from day of year to date

Hello everyone,
I have a file which has day of year in one of the columns (JD=substr($0,72,3)). The bellow scripts shows me the minimum and maximum values of the JD and I would like to convert the JD to date.
Code:
#!/bin/gawk -f
  {
 check=substr($0,1,1)
 if (check == "S") 
 {
  JD=substr($0,72,3);
 {
  if(minJD=="")
 {
  minJD=maxJD=JD
 }
  if(JD>maxJD) 
 {
  maxJD=JD
 }
  if(JD< minJD) 
 {
  minJD=JD
 }
  } 
}
}
END {
today = strftime("%d.%m.%Y")
today2 = strftime("%d.%h.%Y")
time=strftime("%H%M")
print minJD, "  ",maxJD,today,today2,time
 }

Result:
Code:
175    197 17.07.2011 17.Jul.2011 0720

Any help is greatly appreciated

Last edited by Franklin52; 07-17-2011 at 06:31 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-17-2011
What in your result do you want output differently?
# 3  
Old 07-17-2011
I would like to get the date (day.month.year) calculated for JD=175 (24.Jun.2011) and for JD=197 (16.Jul.2011).
# 4  
Old 07-17-2011
Can you give an example from your data file?
# 5  
Old 07-17-2011
Sure, please find attached.
# 6  
Old 07-17-2011
What does lines like these refer to?

S5013 2194 175
S5009 2194 175
# 7  
Old 07-17-2011
S is a code, the next 4 digits represents line, the next 4 are the points (the values of a grid) and the last 3 is the day of the year-JD.

---------- Post updated at 03:53 PM ---------- Previous update was at 03:18 AM ----------

Thanks for your reply, I managed to solve the issue by adding the following code:
Code:
mindate=strftime("%d.%m.%Y",systime()-(todayJD-minJD)*(60*60*24))
maxdate=strftime("%d.%m.%Y",systime()-(todayJD-maxJD)*(60*60*24))

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

2. Shell Programming and Scripting

Julian day to dates in YEAR-MONTH-DAY

hello, I have many files called day001, day002, day003 and I want to rename them by day20070101, day20070102, etc. I need to do it for several years and leap years as well. What is the best way to do it ? Thank you. (1 Reply)
Discussion started by: Ggg
1 Replies

3. Shell Programming and Scripting

Help to generate date from day of the year

Hi I want to convert the day of the year(yyyyddd) to date in mmddyy format Example: input is 2005029 --------> 29th day of 2005 I have to get the output as 01292005 ---> jan 29th 2005 I've to do this in K-Shell There were threads that dealt with coverting date to day of the year but I... (3 Replies)
Discussion started by: sudhamayeev
3 Replies

4. Shell Programming and Scripting

Get day of year

Hi, I wold like to know the day of year from a date in input. I know to get this from sysate with date +%j But from a date in input? :confused: Thanks (2 Replies)
Discussion started by: pinguc
2 Replies

5. AIX

Convert unix timestamp to year month day format ?

Hello, How do I convert unix timestamp value to 'normal' date format - to get year month and day values ? Looks like it's easy to do using GNU date (linux systems). But how do I do tthis on AIX ? I don't want to write C program, any ways to do that using unix shells ? thanks (1 Reply)
Discussion started by: vilius
1 Replies

6. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies

7. Shell Programming and Scripting

awk convert seconds to time of day

Does anyone know of a way to convert "seconds" to time of day in "hh:mm:ss" ? Trying to do in awk with strftime but with no luck. Thanks (2 Replies)
Discussion started by: timj123
2 Replies
Login or Register to Ask a Question