title: Parsing date and time format - Bash
body: <p>I have date and time format like this(yearmonthday):</p>
  
  <pre><code>20141105 11:30:00
  </code></pre>
  
  <p>I need assignment year, month, day, hour and minute values to variable.</p>
  
  <p>I can do it year, day and hour like this:</p>
  
  <pre><code>year=$(awk '{print $1}' log.log | sed 's/^\(....\).*/\1/')
  day=$(awk '{print $1}' log.log | sed 's/^.*\(..\).*/\1/')  
  hour=$(awk '{print $2}' log.log | sed 's/^\(..\).*/\1/')  
  </code></pre>
  
  <p>How can I do this for month and minute?</p>
  
  <p>--</p>
  
  <p>And I need that every line of my log file:</p>
  
  <pre><code>20141105 11:30:00 /bla/text.1
  20141105 11:35:00 /bla/text.2
  20141105 11:40:00 /bla/text.3
  .... 
  </code></pre>
  
  <p>I'm trying read line by line this log file and do this:</p>
  
  <pre><code>mkdir -p "/bla/backup/$year/$month/$day/$hour/$minute"
  mv $file "/bla/backup/$year/$month/$day/$hour/$minute"
  </code></pre>
  
  <p>Here is my not working code:</p>
  
  <pre><code>#!/bin/bash
  LOG=/var/log/LOG
  
  while read line
  do
  
  year=${line:0:4}
  month=${line:4:2}
  day=${line:6:2}
  hour=${line:9:2}
  minute=${line:12:2}
  file=$(awk '{print $3}')
  
  if [ -f "$file" ]; then
  
  printf -v path "%s/%s/%s/%s/%s" $year $month $day $hour $minute
  mkdir -p "/bla/backup/$path"
  mv $file "/bla/backup/$path"
  
  fi
  done &lt; $LOG
  </code></pre>