删除文件中的计数器行号和时间线

删除文件中的计数器行号和时间线

我有一个电影的字幕(sub.srt 或文本文件)文件。但我想知道是否有一种简短的方法可以删除文件的所有行号和时间线。例如

85
00:07:39,250 --> 00:07:41,469
We got to be smart.
We're a ways from being finished.

86
00:07:41,628 --> 00:07:43,380
Shit, I can do this all week.

87
00:07:43,546 --> 00:07:44,547
We're gonna.

88
00:07:44,714 --> 00:07:49,352
We're like the Comanches,
little brother, raiding wherever we please

它必须被证明为

We got to be smart.
We're a ways from being finished.

Shit, I can do this all week.

 We're gonna.

We're like the Comanches,
little brother, raiding wherever we please

我怎样才能达到这个目标?

答案1

使用 的awk段落模式 ( RS=) 会使每个行块被视为输入记录。此外,字段分隔符可以设置为\n从 3 开始打印的字段 - 这假设行号和时间线始终出现在每个记录块内的前两条记录中

awk -F '\n' -v RS= '{for (i=3; i<=NF; ++i) print $i; print ""}' file

We got to be smart.
We're a ways from being finished.

Shit, I can do this all week.

We're gonna.

We're like the Comanches,
little brother, raiding wherever we please

相关内容