0

I need to write a sed script that places the actual text of the subtitles in a srt file on a single line.

If this text originally was split over multiple lines, the line break and possible whitespace must be replaced by a single whitespace.

Input

00:00:12,800 --> 00:00:16,300
I think uh, vice-president of consumer products
or something like that

Output

00:00:12,800 --> 00:00:16,300
I think uh, vice-president of consumer products or something like that

I already got this

N
s/\([a-z]*,*\)\\n/ /g 

but that didn't work. Can someone help me?

3
  • is sed a must? apart from that: so you want to get all the text between 2 timestamps (i see the --> as the prominent pattern here) onto one long line? reading en.wikipedia.org/wiki/SubRip i am under the impression that an empty line separates 2 subtitles ... ?
    – akira
    Feb 21, 2012 at 10:58
  • yes sed is a must, It's a task for school.
    – Jleeeeny
    Feb 21, 2012 at 11:05
  • that's exactly what sed is tricky with(relative to other utilities) because with sed it is not possible to put/use a \n in the find section. You can remove new lines in sed though, as you see from the answer given.
    – barlop
    Nov 17, 2014 at 12:52

1 Answer 1

0
$ sed -n '/-->/{1!{x;s/\n/ /g;p;x};p;n;h;d};H;${x;s/\n/ /g;p}' input.txt

I wouldn't do homework for you. You should read more to interpreter it.


BTW, the awk solution is much easier:

$ awk '/-->/{if(NR!=1)print "";print;next}; {printf "%s",$0}' input.txt

You must log in to answer this question.

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