1

I like GNU/Linux and writing bash scripts to automatize my tasks. But I am a beginner and have a lot of problems with it. So, I have a subtitle file in format like I this(I'm Polish so it's a Polish subtitles):

  00:00:27:W zamierzchłych czasach|ziemia pokryta była lasami.
  00:00:31:Od wieków mieszkały|w nich duchy bogów.
  00:00:37:Człowiek żył w harmonii ze zwierzętami.

I thing you understanding this simple format. The problem is that in the "movie file", before the movie starts is 1:15 of introduction. I want to add to each subtitle file's line 1:15. So the example should look like this:

  00:01:43:W zamierzchłych czasach|ziemia pokryta była lasami.
  00:01:46:Od wieków mieszkały|w nich duchy bogów.
  00:01:52:Człowiek żył w harmonii ze zwierzętami.

Could you help me to write this script?

BTW I'm Polish and I'm still learning English. So if you cannot understand me, write.

4

1 回答 1

1

Here's a solution in awk - probably easier than bash for this kind of problem:

#!/usr/bin/awk -f

BEGIN {
  FS=":"
}

{
  hr = $1
  min = $2
  sec = $3

  sec = sec + 15
  if (sec >= 60) {
    sec = sec - 60
    min = min + 1
  }

  min = min + 1
  if (min >= 60) {
    min = min - 60
    hr = hr + 1
  }

  printf "%02d:%02d:%02d:%s\n", hr, min, sec, $4 
}

Suggestions for improvement welcome!

于 2011-07-26T18:23:45.907 回答