我从sed开始。 任何人都可以引导我如何解决这个问题? 我从这开始,我现在是sed的基本命令:
{0}{20}First subtitle
{30}{50}Second subtitle|New line is made this way.
{70}{100}Third.
{1010}{1033}Fourth etc.
括号中的数字表示字幕应该可见的开始和结束。 让我们有一位翻译人员以这种方式翻译字幕( 我将签署此文(*)):
{0}{20}First subtitle
Translation of the first subtitle.
{30}{50}Second subtitle|New line is made this way.
Translation of the second subtitle.|Second line of translation of the second subtitle.
{70}{100}Third.
Translation of third.
{1010}{1033}Fourth etc.
Translation of fourth etc.
我需要做三件事: 1)分离翻译后的字幕:
{0}{20}Translation of the first subtitle.
{30}{50}Translation of the second subtitle|Second line of translation of the second subtitle.
{70}{100}Translation of third.
{1010}{1033}Translation of fourth etc.
2)与文字分开,两个字幕(用*签名)只有原始的subtiltes并得到这个:
{0}{20}First subtitle
{30}{50}Second subtitle|New line is made this way.
{70}{100}Third.
{1010}{1033}Fourth etc.
3)从1)和2)获取输出并获得带有两个字幕的原始文本(签名*):
{0}{20}First subtitle
Translation of the first subtitle.
{30}{50}Second subtitle|New line is made this way.
Translation of the second subtitle.|Second line of translation of the second subtitle.
{70}{100}Third.
Translation of third.
{1010}{1033}Fourth etc.
Translation of fourth etc.
任何人都可以给我一些建议如何开始?非常感谢。
我应该提一下(应该很清楚),我会这样称呼它:
cat input_file.txt | sed <"program" in sed>
答案 0 :(得分:0)
将字幕文件 file_1
的翻译保存到字幕文件 file_2
后,执行以下命令:
sed -r 's/^[{][0-9]+[}][{][0-9]+[}]//' file_2 | paste -d"\n" file_1 -
答案 1 :(得分:0)
一种方法:
步骤1和2:从(*)中分离出已翻译的副标题和原始副标题(我在下面的脚本中将其称为sub_both
)
sed -r '
/^((\{[0-9]+\}){2}).*/ {
w sub_orig
s//\1/
N
}
s/\n//
w sub_tran
' sub_both
它的作用是:
sub_orig
{digits}{digits}translated line...
sub_tran
第3步:现在我们已sub_orig
和sub_tran
,重建(*)为sub_both_2
paste -d "\n" sub_orig <(sed -r '/^((\{[0-9]+\}){2})//' sub_tran) >sub_both_2
通过sub_tran
预处理 sed
以删除2个数字序列,并将2个文件与换行合并为分隔符。
p / s:<(command)
是进程替换,它会从command
创建一个临时文件。