蚂蚁相当于cut |排序| uniq
在一个Ant任务中,我设置了一个属性,它是一个文件列表。例如蚂蚁相当于cut |排序| uniq
web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob
我想从这个列表中提取一组子目录。在bash我想:
$ cat filename | cut -d'/' -f1 | sort | uniq
business
web
有没有一种方法,我可以在Ant宏中做类似的事情?它也需要在Windows上运行,所以<exec>
不是一个选项。
您可以使用loadresource
task和filterchain来执行此操作。像这样的事情也许:
<property name="list.of.files">
web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob
</property>
<loadresource property="dirs">
<string value="${list.of.files}" />
<filterchain>
<replaceregex pattern="/.*" replace="" />
<sortfilter />
<uniqfilter />
</filterchain>
</loadresource>
<echo message="${dirs}" />
结果:
[echo] business
[echo] web
BUILD SUCCESSFUL
在老版本的Ant(< 1.7),你可以通过出写入属性到一个文件,然后使用loadfile
任务与做同样的filterchain。
['loadresource'](http://ant.apache.org/manual/Tasks/loadresource.html)[[string]](http://ant.apache.org/manual/Types/resources .html#string)资源(和相同的'filterchain')? – matt 2011-06-09 11:34:18
@matt:非常简单,谢谢。我总是忘记了Ant资源的力量。 – 2011-06-09 12:17:25
不是你的问题的答案,而是一个提示 - 你可以用'sort -u'替换'sort | uniq' – Lobo 2011-06-09 03:13:04
啊谢谢你。 bash的魔力永无止境。 – Synesso 2011-06-09 04:25:53