Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Sep 30 '12 at 11:43

This question came from our site for professional and enthusiast programmers.

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 '12 at 21:55
    
What have you tried? –  m.buettner Sep 29 '12 at 21:56
    
@terces907 apologies I misread your question –  Kane Sep 29 '12 at 22:29

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

With GNU sed:

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

This might work for you (GNU sed):

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.