蚂蚁相当于割|排序 |优衣库 [英] Ant equivalent of cut | sort | uniq

查看:18
本文介绍了蚂蚁相当于割|排序 |优衣库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ant 任务中,我设置了一个属性,它是一个文件列表.例如

In an Ant task I set a property which is a list of files. e.g.

web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob

我想从此列表中提取子目录集.在 bash 中,我会:

I would like to extract the set of subdirectories from this list. In bash I'd:

$ cat filename | cut -d'/' -f1 | sort | uniq
business
web

有没有办法在 Ant 宏中做类似的事情?它也需要在 Windows 上运行,所以 不是一个选项.

Is there a way I can do something similar in an Ant macro? It needs to run on Windows too, so <exec> is not an option.

推荐答案

您可以使用 loadresource 任务 带有 filterchain>.大概是这样的:

You can do this using a loadresource task with a filterchain. Something like this perhaps:

<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 任务来执行相同的操作.

In older versions of Ant (<1.7) you could do the same by writing the property out to a file, then using a loadfile task with filterchain.

这篇关于蚂蚁相当于割|排序 |优衣库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆