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 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?

share|improve this question
    
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 '12 at 10:58
    
yes sed is a must, It's a task for school. –  Jleeeeny Feb 21 '12 at 11:05
add comment

1 Answer

up vote 0 down vote accepted
$ 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
share|improve this answer
add comment

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.