Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Sep 30 '12 at 11:43

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

@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
@terces907 apologies I misread your question – Kane Sep 29 '12 at 22:29
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' >

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

You must log in to answer this question.

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