如何使用恶性更改一个文件中的一行? [英] How to change one line in a file using NAnt?
本文介绍了如何使用恶性更改一个文件中的一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用楠更新.js文件中一个特定的行。 该生产线将是这样的:
I need to use NAnt to update one specific line in a .js file. The line will be something like:
global.ServerPath = 'http://server-path/';
我需要一种方法来更新目标服务器的该行的服务器路径的一部分。
ReplaceString是没有好,因为我不知道是什么文件中的路径是,当我更新。
I need a way to update the "server-path" part of that line with that of the destination server.
ReplaceString is no good, since I won't know what the path in the file is when I update it.
任何帮助吗?
在此先感谢
推荐答案
如果字符串::替换
不起作用<正则表达式>
可以做的工作。这是它:
If string::replace
doesn't work <regex>
can do the job. This is it:
<?xml version="1.0" encoding="utf-8" ?>
<project name="replace.line" default="replace">
<target name="replace" descripton="replaces a line">
<property
name="js.file"
value="C:\foo.js" />
<loadfile file="${js.file}" property="js.file.content" />
<regex
input="${js.file.content}"
pattern="(?'BEFORE'.*)global\.ServerPath\s*=\s*'[^']*';(?'AFTER'.*)" />
<echo
file="${js.file}"
message="${BEFORE}global.ServerPath = 'http://bla/';${AFTER}"
append="false" />
</target>
</project>
这篇关于如何使用恶性更改一个文件中的一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文