#!/bin/bash

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 startIndex"
  exit 1
fi

awk -v mindex=$1 'BEGIN{months="JanFebMarAprMayJunJulAugSepOctNovDec"}
  /Day changed/ {Month=int((index(months,$5)+2)/3); Day=$6; Year=$7;}

     /Log opened/ {Month=int((index(months,$5)+2)/3); Day=$6; Year=$8;} 
     ! /(-->)|(<--)|(---)/ {count++; sep=";";
                  w= Year " " Month " " Day " " substr($1, 1, 2) " " substr($1, 4, 5) " 00"; 
                  if ($2 == "*") {
                    pp= $2 sep $3 " "; $3=""; n=4;
                  } else {
                    pp=substr($2, 1, length($2)-1) sep; n=3;}; 
                  $1=""; $2="";
                  print count+mindex-1 sep mktime(w) sep pp substr($0,n);
                 }'

