Eu tenho um arquivo com várias linhas e quero unir as linhas somente se elas se enquadrarem em um padrão específico. Eu sei que posso juntar as linhas com, por exemplo:
$ cat input.txt
1
00:02:34,654 --> 00:02:36,554
Sean, let's go.
2
00:02:38,358 --> 00:02:40,724
Yeah. Detective. we got
a possible 1 87 out on Route 59.
3
00:03:04,584 --> 00:03:06,051
Right this way.
4
00:05:01,301 --> 00:05:03,269
How long has this been here?./
Tuesday.
$ cat input.txt | perl -00 -lpe '$i = 0; s/\n/(++$i > 2) ? " " : "\n"/ge'
1
00:02:34,654 --> 00:02:36,554
Sean, let's go.
2
00:02:38,358 --> 00:02:40,724
Yeah. Detective. we got a possible 1 87 out on Route 59.
3
00:03:04,584 --> 00:03:06,051
Right this way.
4
00:05:01,301 --> 00:05:03,269
How long has this been here?./ Tuesday.
Mas, como posso resolver se a linha se enquadra no padrão (somente se tiver um '/'
)?. Então, neste caso, o resultado que eu gostaria de alcançar seria:
1
00:02:34,654 --> 00:02:36,554
Sean, let's go.
2
00:02:38,358 --> 00:02:40,724
Yeah. Detective. we got
a possible 1 87 out on Route 59.
3
00:03:04,584 --> 00:03:06,051
Right this way.
4
00:05:01,301 --> 00:05:03,269
How long has this been here?./ Tuesday.
/\//
se a linha contiver/
N
adicione nova linha e próxima linhas/\n/ /
replcae nova linha com um espaço.