【发布时间】:2016-05-28 16:51:40
【问题描述】:
我正在运行一个简单的 Perl 脚本,它将所有以 \txt 开头的行复制到 \xtx。到目前为止,一切都很好。
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 ... 开头的行...
【问题讨论】:
-
duplicates all lines starting with \txt=s/^(\\txt )(.*)/$1$2\n\\xtx $2/mg -
您需要
s///egeval 表单来执行此操作。通过空格保留/缩小格式会有点乏味,但可行。 -
您能否提供真实的示例字符串,因为我认为您的描述不是很清楚。
-
@CasimiretHippolyte 我刚刚用一些真实数据编辑了这个问题。