Reputation: 734
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.
Upvotes: 0
Views: 92
Reputation: 203324
Depending on whether or not any of those x
s 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
Upvotes: 2