0

我们在 linux 中处理了很多 srt 文件以生成衍生文件,但其中一些具有ctrl-M字符,因为它们是在 windows 中生成的。现在我放了两个命令来检查并取出隐藏的字符

tr -d '\015' <${file}.srt >${file}.srt

awk '/^$/{ if (! blank++) print; next } { blank=0; print }'  ${file}.srt | tee ${file}.srt

但我仍然有 srt 文件通过命令滑过并且仍然有ctrl-M字符。在这种情况下,有没有人有一个解决方案,只在每条微妙的线条之间保持空行?所以如果预处理的 srt 文件看起来像

1
00:00:05,569 --> 00:00:07,569
Welcome to this overview of ShareStream, 


2
00:00:07,820 --> 00:00:11,940
which is a new digital streaming service
from Information Technology Services


3
00:00:11,940 --> 00:00:13,740
at the University of Iowa.

取出 ctrl-M 字符或多余的空格行后应该是

1
00:00:05,569 --> 00:00:07,569
Welcome to this overview of ShareStream, 

2
00:00:07,820 --> 00:00:11,940
which is a new digital streaming service
from Information Technology Services

3
00:00:11,940 --> 00:00:13,740
at the University of Iowa.

任何帮助表示感谢!

4

1 回答 1

1

删除那些 line-end control-M 的 UNIX 命令是

dos2unix

将记录之间的多个空行压缩为一个空行的 UNIX 命令是:

awk -v RS= -v ORS='\n\n' '1'
于 2018-05-03T20:06:17.433 回答