用静态值替换XML标签值匹配的前两个字符
我正在尝试替换XML TAG的前两个字符< linestyle>< color>
value与00
如果模式匹配不是。
xml
<?xml version="1.0" encoding="UTF-8"?>
<LineStyle>
<color>ff969696</color>
</LineStyle>
<color>ff969696</color>
<LineStyle>
<color>e680e680</color>
</LineStyle>
<color>e680e680</color>
<LineStyle>
<color>e680f7f7</color>
</LineStyle>
<color>e680f7f7</color>
<LineStyle>
<color>e67c88f4</color>
</LineStyle>
<color>e67c88f4</color>
ex。,&lt; linestyle&gt;&lt; color&gt; ff ......
或&lt; linestyle&gt; e6 ......
将用&lt; linestyle&gt;&gt; 00 ......
等等。
尝试的代码
sed 's/<LineStyle><color>[0-9][a-z]*/<LineStyle><color>00*/g'
I am trying to replace the first two characters of an XML tag <LineStyle><color>
value match with 00
if the pattern match isn't 00
.
XML
<?xml version="1.0" encoding="UTF-8"?>
<LineStyle>
<color>ff969696</color>
</LineStyle>
<color>ff969696</color>
<LineStyle>
<color>e680e680</color>
</LineStyle>
<color>e680e680</color>
<LineStyle>
<color>e680f7f7</color>
</LineStyle>
<color>e680f7f7</color>
<LineStyle>
<color>e67c88f4</color>
</LineStyle>
<color>e67c88f4</color>
Ex., a pattern match of <LineStyle><color>ff......
or <LineStyle><color>e6......
would be replaced with <LineStyle><color>00......
and so on.
Attempted Code
sed 's/<LineStyle><color>[0-9][a-z]*/<LineStyle><color>00*/g'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此perl单线:
perl单线使用以下命令行标志:
-e
:告诉Perl在线寻找代码,而不是在文件中。-p
:一次在输入一行上循环,将其分配给$ _
默认情况下。添加打印$ _
在每个循环迭代后。-i.bak
:在现场编辑输入文件(覆盖输入文件)。在覆盖之前,通过将其名称附加到Extension.bak
来保存原始文件的备份副本。-0777
:全部slurp文件。正则使用这些修饰符:
/g
:反复匹配模式。/x
:忽略空格和评论,以获取可读性。/m
:允许多行匹配。/s
:允许。
匹配新线。另请参见:
perldoc perlrun
:
:perl Parrications(Regexes)perldoc perllre
perldoc perlrequick
:perl Prinestions快速启动Use this Perl one-liner:
The Perl one-liner uses these command line flags:
-e
: Tells Perl to look for code in-line, instead of in a file.-p
: Loop over the input one line at a time, assigning it to$_
by default. Addprint $_
after each loop iteration.-i.bak
: Edit input files in-place (overwrite the input file). Before overwriting, save a backup copy of the original file by appending to its name the extension.bak
.-0777
: Slurp files whole.The regex uses these modifiers:
/g
: Match the pattern repeatedly./x
: Ignore whitespace and comments, for readability./m
: Allow multiline matches./s
: Allow.
to match a newline.SEE ALSO:
perldoc perlrun
: how to execute the Perl interpreter: command line switchesperldoc perlre
: Perl regular expressions (regexes)perldoc perlrequick
: Perl regular expressions quick start