Code:
awk '
BEGIN { month=1; flag=0; theYear=2000; dayOfYear=0 }
function DoyToDate(Year, Doy)
{
theYear = int("20"Year)
dOfYear=Doy
dayOfYear=int(dOfYear)
{ if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } #january
{ if ( flag == 0 ) { if (( theYear % 4 != 0) && (dayOfYear > 28 )) { month += 1; dayOfYear -= 28 } else {
{ if (( theYear % 4 == 0 ) && (dayOfYear > 29)) { month += 1; dayOfYear -= 29 } else { flag = 1}}}}} #february
{ if ( flag == 0 ) { if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } } #march
{ if ( flag == 0 ) { if ( dayOfYear > 30 ) { month += 1; dayOfYear -= 30 } else { flag = 1 } } } #april
{ if ( flag == 0 ) { if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } } #may
{ if ( flag == 0 ) { if ( dayOfYear > 30 ) { month += 1; dayOfYear -= 30 } else { flag = 1 } } } #june
{ if ( flag == 0 ) { if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } } #july
{ if ( flag == 0 ) { if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } } #august
{ if ( flag == 0 ) { if ( dayOfYear > 30 ) { month += 1; dayOfYear -= 30 } else { flag = 1 } } } #september
{ if ( flag == 0 ) { if ( dayOfYear > 31 ) { month += 1; dayOfYear -= 31 } else { flag = 1 } } } #october
{ if ( flag == 0 ) { if ( dayOfYear > 30 ) { month += 1; dayOfYear -= 30 } else { flag = 1 } } } #november
{ if ( int (theYear) < 10 ) theYear="0"theYear }
{ if ( month < 10 ) month="0"month }
{ if ( dayOfYear < 10 ) dayOfYear="0"dayOfYear }
}
{ for( i = 1; i <= 5; i++ ) printf "%s ", $i }
{ printf "%18s %18s %18s ", substr($6,1,index($6,"_")-1), substr($7,1,index($7,"_")-1), substr($8,1,index($8,"_")-1) }
{
DoyToDate(int(substr($9, 1, 2)),substr($9, 4, 3))
printf "%s,%s ",dayOfYear"."month"."theYear,substr($9,8,8)
month=1; flag=0; theYear=2000; dayOfYear=0
}
{
if($10 == "000,00:00:00")
{ printf "%s ","-------------------" }
else
{
{
if(int(substr($9, 4, 3)) > int(substr($10,1,3)))
{
DoyToDate(int(substr($9, 1, 2)) + 1, substr($10, 1, 3))
}
else
{
DoyToDate(int(substr($9, 1, 2)), substr($10, 1, 3))
}
}
{
printf "%s,%s ",dayOfYear"."month"."theYear,substr($10,5,8)
month=1; flag=0; theYear=2000; dayOfYear=0
}
}
}
{
{
if(int(substr($9, 4, 3)) > int(substr($11,1,3)))
{
DoyToDate(int(substr($9, 1, 2)) + 1, substr($11, 1, 3))
}
else
{
DoyToDate(int(substr($9, 1, 2)), substr($11, 1, 3))
}
}
{
printf "%s,%s ",dayOfYear"."month"."theYear,substr($11,5,8)
month=1; flag=0; theYear=2000; dayOfYear=0
}
}
{
print ""
}
' infile.txt >outfile.txt