Change the date format

Hi all,

I have a file that every line starts with the date and time. The format is like YYYYMMDDHHMM and I woulk like to change it to MM/DD/YY<space>HH:MM.
I tried to figure out a way to do it with sed, but I don't know how I could reorganize the digits of the first format. Does anyone have any idea?

Thanks a lot

Backup your data before executing the command:

sed > _new_ 's#^..\(..\)\(..\)\(..\)\(..\)\(..\)#\2/\3/\1 \4:\5#' infile &&
  mv -- _new_ infile

Some sed implementations support the -i (in-place) option,
if you have one of those, you could use something like this:

sed -i.orig 's#^..\(..\)\(..\)\(..\)\(..\)\(..\)#\2/\3/\1 \4:\5#' infile

And, of course, you can always use Perl:

perl -i.orig -pe's#^..(..)(..)(..)(..)(..)#$2/$3/$1 $4:$5#' infile

If you want to be sure to match only digits at the beginning of the lines,
you should change the dots (.) with [0-9] (with GNU sed and Perl you could use \d too)