0

I have extremely large log file that I need to process and save for csv format every hour.

the format is like below ( this line also after removed many characters using sed)

Apr-05 11:10:12 xxxx xxx xxxx xxxx xxxx

I need to save this as

04-05 11:10:12,xxxx,xxx,xxxx,xxxx,xxxx

I tried set variable using $1 and try to convert it using GNU date but not working

awk -v fixdate="($1 +%m-)" '{print fixdate"-"$2" "$3 "," $x "," $y "," $z}'

I prefer single line method to do this.

How can I assign $1 (Apr-05) part to awk variable and process it with GNU date before printing.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
rafalefighter
  • 714
  • 2
  • 11
  • 39

1 Answers1

2

Depending on whether or not any of those xs can be a -, this might be all you need:

$ awk -F'-' '{
    gsub(/ /,",",$2); sub(/,/," ",$2);
    printf "%02d-%s\n", (index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)+2)/3, $2
}' file
04-05 11:10:12,xxxx,xxx,xxxx,xxxx,xxxx
Ed Morton
  • 188,023
  • 17
  • 78
  • 185