长时间读者第一次问问.
我正在编写一些我需要编辑时间戳的vtt(隐藏式字幕)文件.该文件的格式如下:
177
00:07:37.450 --> 00:07:39.690
- [Liz] How would you suggest an organization devise
178
00:07:39.690 --> 00:07:41.719
the accountabilities for culture?
179
00:07:41.719 --> 00:07:43.690
- [Tamara] It is a shared accountability
Run Code Online (Sandbox Code Playgroud)
我编写了以下代码来读取文件,计算新的时间戳(慢5%)并吐出新的时间戳:
from sys import argv
script, filename = argv
adjustment = input("Adjustment multiplier: ")
video = open(filename, "r+")
lines = video.readlines()
video.seek(0)
for l in lines:
if l[:2] == "00":
#here I've omitted a lot of calculations to turn the timestamps
#into milliseconds, apply the adjustment …Run Code Online (Sandbox Code Playgroud) 我需要使用bash脚本从文件中删除特定的行号.
我使用-n选项从grep命令获取行号.
我出于各种原因无法使用sed,其中最重要的是它没有安装在这个脚本需要运行的所有系统上,并且安装它不是一个选项.
awk是不可能的,因为在测试中,在具有不同UNIX/Linux操作系统(RHEL,SunOS,Solaris,Ubuntu等)的不同机器上,它在每个机器上给出(有时是非常)不同的结果.所以,没有awk.
有问题的文件只是一个平面文本文件,每行有一条记录,因此除了按行删除行之外,不需要做任何花哨的事情.
如果可能的话,我需要避免做一些事情,比如提取文件的内容,不包括我想要的行,然后覆盖原始文件.