我正在尝试使用Phing将文本附加到文件中的特定位置。
使用Phing的默认<append>
将文字放在文件的末尾,我也尝试使用<filterchain>
,但它不支持<append>
参数。
示例:
我需要在第2行和第3行之间附加文本Hello World
。
//config.php
line1
line2
line3
在第3行之后附加文字的代码
<append destFile="\config.php"
text="${line.separator} Hello World; ${line.separator}" />
除了使用line2
删除replace
并将其重新添加为line2 ${line.separator} Hello World
之外,是否还有更好的内置解决方案来完成此操作?
PS。我不能使用占位符或令牌,因为文件是从远程源下载的,无法更改。
答案 0 :(得分:0)
我提出的唯一解决方案是在您想要包含数据之前替换现有文本,然后将其添加回来。
例如:
<reflexive file="\config.php">
<filterchain>
<replaceregexp>
<regexp pattern="line2" replace="line2 ${line.separator} Hello World" />
</replaceregexp>
</filterchain>
</reflexive>