join lines in file

I have a file like this:
---------------------------------------------------------------

26
00:04:48,440 --> 00:04:51,440
I don't know why he can't just do
the Great Apache Flaming Arrow Act.

27
00:04:52,440 --> 00:04:54,839
Didn't you tell him
to use the gopher snake?

28

------------------------------------------------------------------
I want to join two lines but only the lines with letters and
when the two lines have together not more than for example 50 characters.

I try the next script and the output of the script show me the lines that can be joined but the script join also the lines with numbers.
When I'm change punct with alpha than the script doesn't work anymore.
And I don't know how to save the file.
---------------------------------------------------------------

#!/bin/bash
clear
tr -d '\r' < file >newfile 
together=`cat file | sed '/[^[:punct:]],*$/{N;s/\n/ /;}'`
echo "$together" | while read line
do
count=`echo "$line" | wc -c`
if [ "$count" -lt 50 ]
then 
echo "$line"
fi
done

--------------------------------------------------------------------
If someone know a solution, thanks very much.

How about using awk:

awk 'length($3$4)<50{$3=$3" "$4;NF=3}1' RS= OFS='\n' ORS='\n\n' FS='\n' infile
1 Like