相关疑难解决方法(0)

在文本文件中的每4行读取,编辑和写入

长时间读者第一次问问.

我正在编写一些我需要编辑时间戳的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)

python

5
推荐指数
1
解决办法
71
查看次数

使用sed或awk从文件中删除特定行

我需要使用bash脚本从文件中删除特定的行号.

我使用-n选项从grep命令获取行号.

我出于各种原因无法使用sed,其中最重要的是它没有安装在这个脚本需要运行的所有系统上,并且安装它不是一个选项.

awk是不可能的,因为在测试中,在具有不同UNIX/Linux操作系统(RHEL,SunOS,Solaris,Ubuntu等)的不同机器上,它在每个机器上给出(有时是非常)不同的结果.所以,没有awk.

有问题的文件只是一个平面文本文件,每行有一条记录,因此除了按行删除行之外,不需要做任何花哨的事情.

如果可能的话,我需要避免做一些事情,比如提取文件的内容,不包括我想要的行,然后覆盖原始文件.

unix linux bash

1
推荐指数
1
解决办法
9010
查看次数

标签 统计

bash ×1

linux ×1

python ×1

unix ×1