create csv in ksh from tricky log file

hi guys, trying to create a csv from a tricky log file in ksh,

using 'awk '{print $1" "$14" "$15" "$16" "$17" "$18" "$19}' >> $TMP_FILE' on another set of files I have an output file with hundreds of lines in which looks like so:

ABC_DEFGHI_16_JKLMNP11.20101115_095412_374.log:09:54:29.579 cars amount 29, total cars 70
ABC_DEFGHI_17_JKLMNP11.20101115_095412_374.log:09:54:29.585 cars amount 34, total cars 43
ABC_DEFGHI_11_JKLMNP11.20101115_095412_374.log:09:54:29.601 cars amount 22, total cars 44

but from the above log file i'm trying to create 2 csv files which looks like so:

date,time,cars amount
15/11/2010,09:54:29,29
15/11/2010,09:54:29,34
15/11/2010,09:54:29,22

and the other one...

date,time,cars amount
15/11/2010,09:54:29.579,29
15/11/2010,09:54:29.585,34
15/11/2010,09:54:29.601,22

could anyone provide an example awk or cut to achieve the above? it's proving tricky to achieve with cut! thanks

Try:

awk -F'[ \t,_:.]*' '{print $5","$9":"$10":"$11"."$15}' infile
awk -F'[ \t,_:.]*' '{print $5","$9":"$10":"$11"."$12","$15}' infile
1 Like
awk -F'[ \t,_:.]*' '{print $5","$9":"$10":"$11"."$12}' infile

that one returns:

richard@opensolaris:~/Shell$ awk -F'[ \t,_:.]*' '{print $5","$9":"$10":"$11"."$12}' junk.log
20101115,09:54:29.579
20101115,09:54:29.585
20101115,09:54:29.601

2nd one works though! :b: :

richard@opensolaris:~/Shell$ awk -F'[ \t,_:.]*' '{print $5","$9":"$10":"$11"."$12","$15}' junk.log
20101115,09:54:29.579,29
20101115,09:54:29.585,34
20101115,09:54:29.601,22

is it possible to get the date in the format 15/11/2010?

could you take me through what this part '-F'[ \t,_:.]' is doing, I understand the rest but not that part much appreciated!

Based from scrutinizer command:

$ awk -F'[ \t,_:.]*' '{print substr($5,7,2)"/"substr($5,5,2)"/"substr($5,1,4)","$9":"$10":"$11"."$12}' a
15/11/2010,09:54:29.579
15/11/2010,09:54:29.585
15/11/2010,09:54:29.601