2

I have a problem with subtitle file(.srt). It doesn't work. And i want to add some parameter to many lines of text with Regex in Sed program.

changes from this pattern:

00:00:00 --> 00:00:06

to this:

00:00:00,000 --> 00:00:06,000

",000" added after "hh:mm:ss"

How to write regex for this problem?

2
  • 1
    @Kane I asking about regex for change pattern "hh:mm:ss --> hh:mm:ss" to "hh:mm:ss,000 --> hh:mm:ss,000". I think regex is a kind of programming.
    – terces907
    Sep 29, 2012 at 21:55
  • @terces907 apologies I misread your question
    – Kane
    Sep 29, 2012 at 22:29

3 Answers 3

1

Use the following:

sed 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/&,000/g' your_file.srt > new_file.srt

It will replace every occurrence of time in the format XX:XX:XX with XX:XX:XX,000. & is a special character which refers to the pattern found.

1

With GNU sed:

sed -r 's/(([0-9]{2}:){2}[0-9]{2})/\1,000/g'
1

This might work for you (GNU sed):

sed -r 's/((^|\s)[0-9]{2}(:[0-9]{2}){2})(\s|$)/\1,000\4/g' file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .