[ILUGC] Re: How to convert 20:40.280 (mm.ss.SSS) to 00:20:40.280 (hh.mm.ss.SSS) in Bash

  • From: Baskar Selvaraj <baskar@xxxxxxxxxxxx>
  • To: ilugc <ilugc@xxxxxxxxxxxxx>
  • Date: Sat, 5 Sep 2020 21:16:16 +0530

sed -e 's/^[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9]/00:&/1' -e
's/[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9]/00:&/2' file

input:

09:54.740 --> 10:01.740
10:01.740 --> 15:20.230
1:02:50.570 --> 1:04:39.160

output:

00:09:54.740 --> 00:10:01.740
00:10:01.740 --> 00:15:20.230
1:02:50.570 --> 1:00:04:39.160 (this is affected)


Though this may not be a good solution, it still does the job (just
added two more expressions).

sed -e 's/^[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9]/00:&/1' -e
's/[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9]/00:&/2' -e 's/^1:/01:/1' -e
's/--> 1:00/--> 01/1' file

S. Baskar
---
Mailing List Guidelines: https://ilugc.in/mailing-list-guidelines
Web: http://ilugc.in/
Internet Relay Chat: #ilugc on irc.freenode.net

Other related posts: