Search code examples
unixawksed

how to modify columun time format


I have several files with a datetime in one column and I'm trying to change the time from '%hh.%nn.%ss' to '%hh:%nn:%ss'. the difficulty is that the position of the TIME column changes depending on the file example

1-File 1:
22;23243;1;2013-08-23-15.46.34;

2- File 2 :
0000054;0000001;00496999999;0000;2012-02-29-13.40.18;001

Thank you

sed in unix command to solve the problem


Solution

  • This might work for you (GNU sed):

    sed -E 's/(....-..-..-..)\.(..)\.(..)/\1:\2:\3/' file
    

    Pattern match and use back references to replace .'s by :'s.