【发布时间】:2015-09-30 10:16:00
【问题描述】:
我写了一个非常简单的 bash 脚本:
#!/bin/bash
nLine=$(awk '/text_to_parse/{ print NR; exit }' testFile.xml)
echo "LINE = $nLine"
sed -e "${nLine}s/.*/new text/" < testFile.xml
echo
cat testFile.xml
exit 0
执行返回:
LINE = 8
<Test>
<Name>First Test</Name>
<Version>1.0</Version>
<Command>new text</Command>
</Test>
<Test>
<Name>First Test</Name>
<Version>1.0</Version>
<Command>text_to_parse</Command>
</Test>
永远不会应用修改。文件可以修改..
-rwxrwxrwx 1 root root 290 Jan 1 00:23 testFile.xml
【问题讨论】:
-
您确定这是您的
xml和您的shell 脚本吗?LINE应该是 4,你的sed调用应该替换整行而不是text_to_parse,不是吗?