How to remove the milliseconds from timestamps with sed?

前端 未结 5 1743
迷失自我
迷失自我 2021-01-27 03:48

My input file is as follows:

12/13/2011,07:14:13.724,12/13/2011 07:14:13.724,231.56.3.245,LasVegas,US

I wish to get the following:

<         


        
5条回答
  •  生来不讨喜
    2021-01-27 04:14

    You were near but some characters are special in sed (in my version, at least): {, }, (, ), but not :. So you need to escape them with a back-slash.

    And \1 takes expression between paretheses, it should be the first part until seconds, not the second one.

    A modification of your version could be:

    sed "s/\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)\.[0-9]\{1,3\}/\1/g" input_file.csv > output.csv
    

提交回复
热议问题