Reformatting date times with awk
<p>I have a file with rows like this:</p>

<pre><code>2012/04/08 15:00,207
2012/04/08 16:00,180
</code></pre>

<p>I want to format the dates such that the file looks like:</p>

<pre><code>08/04/2012 15:00,207
</code></pre>

<p>Awk would seem to be the right tool, but I can't get it to capture groups correctly. I've tried something like the following (<a href="https://stackoverflow.com/questions/18453057/use-sed-or-awk-to-fix-date-format">Use sed or awk to fix date format</a>):</p>

<p><code>awk '
    BEGIN { FS = OFS = "," } 
    { split($1, date, /\// )
      $1 = date[3] "-" date[2] "-" date[1] " " date[4]
      print $0 
    }
' $FILE</code></p>

<p>But it leaves with me data like this:</p>

<pre><code>08 15:00-04-2012,207
</code></pre>

<p>Awk's split is obviously interpreting the time as part of the year field of the date string, and I can't seem to find a way to split it off separately. I've tried a number of different things like colons or escaped spaces in the split delimiter field but all give syntax error. Have looked at awk split's documentation and was not enlightened by it.</p>