ファイルからカウンター行番号とタイムラインを削除する

ファイルからカウンター行番号とタイムラインを削除する

映画の字幕(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=各行ブロックは入力レコードとして処理されます。フィールド区切り記号は、3から印刷されるフィールドに設定することもできます\n。これは、行番号とタイムラインが常に各レコードブロック内の最初の2つのレコードに表示されると想定されます。

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

おすすめ記事