テキスト/srtファイルの編集

テキスト/srtファイルの編集

次の.srtファイルがあります。

入力ファイル

1
00:00:17,920 --> 00:00:21,159
The essential is invisible to the eye. 3

2
00:00:21,160 --> 00:00:22,559
This phrase comes from 4

3
00:00:22,560 --> 00:00:25,039
As if saying goodbye saddens me, 5

各会話の後に数字があることがわかります(例: '...eye.'の後には3、'...from'の後には4が続きます)。この数字を削除したいです。

期待される出力ファイル

1
00:00:17,920 --> 00:00:21,159
The essential is invisible to the eye.

2
00:00:21,160 --> 00:00:22,559
This phrase comes from

3
00:00:22,560 --> 00:00:25,039
As if saying goodbye saddens me,

この番号を削除する賢明な方法はありますか? Ubuntu 22.04を使用しています。

ベストアンサー1

使用GNU awk

$ awk '/\s+[0-9]+\s*$/{NF--}1'
$ awk '{sub(/[[:space:]]+[0-9]+[[:space:]]*$/,"")}1'

または

$ awk '/[[:alpha:]]+/ && $NF ~ /^[[:digit:]]+$/{$NF=""}1' file

おすすめ記事