我正在运行一个简单的Perl脚本,它复制了所有以\txt
开头到\xtx
的行。到现在为止还挺好。Perl脚本搜索/替换和转换结果
use strict;
use warnings;
$^I = '.bak';
while (<>) {
s/(\\txt)(.*)/$1$2\n\\xtx $2/g;
print;
}
现在我想“擦洗”所有的新线开始\\xtx
和
删除所有非单词字符:即非字母,但保持字符,任何字符变音符号
将所有内容转换为小写。
而这正是我的基本的编程技能结束
我的文本文件看起来像这样:
\txt Text (.) with [ symbols and Num[bers (.2) and cháractẽrs with diacrítics
\abc More text ...
我的剧本至今生产:
\txt Text (.) with [ symbols and Num[bers (.2) and cháractẽrs with diacrítics
\xtx Text (.) with [ symbols and Num[bers (.2) and cháractẽrs with diacrítics
\abc More text ...
而且我想实现:
\txt Text (.) with [ symbols and Num[bers (.2) and cháractẽrs with diacrítics
\xtx text with symbols and numbers and cháractẽrs with diacrítics
\abc More text ...
任何帮助非常感谢!
编辑:
这里有一个真实的例子字符串:
\_sh v3.0 400 Text3
\ref 2013-05-01_08.36.14 001
\txt Djawy (.) de osẽ[ma (.2) EDJu::
\fts Te equivocaste, saliste,
\fte
\ELANParticipant #TBGD
\ELANBegin 00:00:05.367
\ELANEnd 00:00:06.521
\dt 26/May/2016
\ref 2013-05-01_08.36.14 002
\txt [A;;;;;;;;;;;;;
\fts A;;;;;;;;;;;;;
\fte
...
...一切都应该保持原样,除了开始\ TXT线...
'重复所有行开始\ txt' ='S/^(\\ TXT)(。*)/ $ 1 $ 2 \ n \\ xtx $ 2/mg' – sln
您需要使用///例如'eval表单来执行此操作。通过空格保存/缩小格式将会有点乏味,但是可行。 – sln
您能否提供真实的示例字符串,因为我认为您的描述不是很清楚。 –