ant修改文件中的内容 replace命令的使用
2014-10-24 11:18
405 查看
一、replace命令
<replacefilter token="@MIDLET@" value="${app.midlet}"/>
<replacefilter token="@JAR@" value="${app.project}"/>
<replacefilter token="@FILESIZE@" value="${size}"/>
<replacefilter token="@DESCRIPTION@" value="${app.description}"/>
上面的replace命令用起来很简单,但没有办法做正则匹配,如果要替换的字符串,是需要用正则来描述的,可以用replaceregexp
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
byline="true" 表示替换所有满足条件的字符串,若设为false,则只会替换第一个满足正则表达式的字符串
pattern="[1-9][0-9]{4,}"表示QQ号码的正则表达式,当然,你也可以根据需求,替换成其他正则表达式
expression="6356351" 表示将满足条件字符串替换成6356351
<fileset file="test.html"/> 表示在test.html这个文件中进行查找和替换,你也可以设置为查找多个文件,具体方法请在网上搜索fileset 的相关配置
A.替换某一文件中的字符串
<property name="temp.newstring" value="hello world" />
<replace file ="base/testing.txt" token="@temp@" value="${temp.newstring}" />
解释:token是需要替换的标记;value是新值,将testing.txt文件中的@temp@替换为hello world。
B.替换某个文件夹中存在特定标记(@CHARSET@)的文件
<property name="webapp.charset" value="UTF-8" />
<replace dir="temp" token="@CHARSET@" value="${webapp.charset}"/>
解释:查询temp目录中的所有文件,将文件中存在@CHARSET@标记的内容替换为${webapp.charset}变量值。
C.批量替换
<replace dir="dist" includes="${app.project}.jad" encoding="UTF-8">
<replacefilter token="@NAME@" value="${app.name}"/>
<replacefilter token="@VENDOR@" value="${app.vendor}"/>
<replacefilter token="@PRICE@" value="${app.price}"/>
</replace>
二、replaceregexp命令
例子:
</replaceregexp>
作用:将test.html中的QQ号码替换成6356351这串数字
<replacefilter token="@MIDLET@" value="${app.midlet}"/>
<replacefilter token="@JAR@" value="${app.project}"/>
<replacefilter token="@FILESIZE@" value="${size}"/>
<replacefilter token="@DESCRIPTION@" value="${app.description}"/>
上面的replace命令用起来很简单,但没有办法做正则匹配,如果要替换的字符串,是需要用正则来描述的,可以用replaceregexp
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
byline="true" 表示替换所有满足条件的字符串,若设为false,则只会替换第一个满足正则表达式的字符串
pattern="[1-9][0-9]{4,}"表示QQ号码的正则表达式,当然,你也可以根据需求,替换成其他正则表达式
expression="6356351" 表示将满足条件字符串替换成6356351
<fileset file="test.html"/> 表示在test.html这个文件中进行查找和替换,你也可以设置为查找多个文件,具体方法请在网上搜索fileset 的相关配置
A.替换某一文件中的字符串
<property name="temp.newstring" value="hello world" />
<replace file ="base/testing.txt" token="@temp@" value="${temp.newstring}" />
解释:token是需要替换的标记;value是新值,将testing.txt文件中的@temp@替换为hello world。
B.替换某个文件夹中存在特定标记(@CHARSET@)的文件
<property name="webapp.charset" value="UTF-8" />
<replace dir="temp" token="@CHARSET@" value="${webapp.charset}"/>
解释:查询temp目录中的所有文件,将文件中存在@CHARSET@标记的内容替换为${webapp.charset}变量值。
C.批量替换
<replace dir="dist" includes="${app.project}.jad" encoding="UTF-8">
<replacefilter token="@NAME@" value="${app.name}"/>
<replacefilter token="@VENDOR@" value="${app.vendor}"/>
<replacefilter token="@PRICE@" value="${app.price}"/>
</replace>
二、replaceregexp命令
例子:
</replaceregexp>
作用:将test.html中的QQ号码替换成6356351这串数字
相关文章推荐
- Ubuntu下,使用ls命令显示文件颜色相关内容及修改
- Ubuntu下使用ls命令显示文件颜色相关内容及修改
- Ubuntu下使用ls命令显示文件颜色相关内容及修改
- 基于命令的批量修改文件内容
- 小技巧: 使用shell命令修改多个文件(转)
- linux下vi命令 修改文件及保存的使用方法
- 基于命令的批量修改文件内容
- Linux中如何使用命令修改文件所属用户组?
- android使用ant自动打包(包括更改文件中的内容)
- 基于命令的批量修改文件内容
- 移动硬盘文件内容发生错误,删除不掉,修改不了请使用chkdsk工具修复
- shell使用汇总4——文件内容统计命令
- 使用while和read命令读取文件内容
- CMD文件中用FOR命令读取文本文件内容到变量,以及和PsExec搭配使用的方法和例子
- linux 中使用ls命令对文件进行排序-- 基于文件大小或者修改时间
- 我使用过的Linux命令之sync - 强制将内存中的文件缓冲内容写到磁盘
- 使用FSO修改文件特定内容的函数
- linux终端下修改文件名及文件内容的命令
- 基于命令的批量修改文件内容
- 基于命令的批量修改文件内容