Note that there are some explanatory texts on larger screens.

plurals
  1. POAwk/Perl convert textfile to csv with sensible format
    primarykey
    data
    text
    <p>I have a historical autogenerated logfile with the following format that I would like to convert to a csv file prior to uploading to a database</p> <pre><code>-------------------------------------- Thu Jul 8 09:34:12 BST 2010 BLUE Head 1 Duration = 20 s Activity = 14.9 MBq Sensitivity = 312 cps/MBq -------------------------------------- Thu Jul 8 09:34:55 BST 2010 BLUE Head 1 Duration = 20 s Activity = 14.9 MBq Sensitivity = 318 cps/MBq -------------------------------------- Thu Jul 8 10:13:39 BST 2010 RED Head 1 Duration = 20 s Activity = 14.9 MBq Sensitivity = 307 cps/MBq -------------------------------------- Thu Jul 8 10:14:10 BST 2010 RED Head 1 Duration = 20 s Activity = 14.9 MBq Sensitivity = 305 cps/MBq -------------------------------------- Mon Jul 19 10:11:18 BST 2010 BLUE Head 1 Duration = 20 s Activity = 12.4 MBq Sensitivity = 326 cps/MBq -------------------------------------- Mon Jul 19 10:12:09 BST 2010 BLUE Head 1 Duration = 20 s Activity = 12.4 MBq Sensitivity = 333 cps/MBq -------------------------------------- Mon Jul 19 10:13:57 BST 2010 RED Head 1 Duration = 20 s Activity = 12.4 MBq Sensitivity = 338 cps/MBq -------------------------------------- Mon Jul 19 10:14:45 BST 2010 RED Head 1 Duration = 20 s Activity = 12.4 MBq Sensitivity = 340 cps/MBq -------------------------------------- </code></pre> <p>I would like to convert the logfile to the following format</p> <pre><code>Date,Camera,Head,Duration,Activity 08/07/10,BLUE,1,20,14.9 08/07/10,BLUE,1,20,14.9 08/07/10,RED,1,20,14.9 08/07/10,RED,1,20,14.9 </code></pre> <p>I have used awk to get me close to what I wish </p> <pre><code>awk 'BEGIN {print "Date,Camera,Head,Duration,Activity";RS = "--------------------------------------"; FS="\n";}; {OFS=",";split($3, a, " ");split($4,b, " "); split($5,c," ");print $2,a[1],a[3],b[3],c[3]}' sensitivity.txt &gt; sensitivity.csv </code></pre> <p>which gives me</p> <pre><code>Date,Camera,Head,Duration,Activity ,,,, Thu Jul 8 09:34:12 BST 2010,BLUE,1,20,14.9 Thu Jul 8 09:34:55 BST 2010,BLUE,1,20,14.9 Thu Jul 8 10:13:39 BST 2010,RED,1,20,14.9 Thu Jul 8 10:14:10 BST 2010,RED,1,20,14.9 </code></pre> <p>How can I</p> <p>(a) get rid of the 4 output field separators in line 4 (b) Convert the date format from Thu Jul 8 09:34:12 BST 2010 to DD/MM/YY (Can I do this in pure awk or by piping to perl)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload