Ant equivalent of cut | sort | uniq

我的未来我决定 提交于 2019-12-08 01:26:10

问题


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

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

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.


回答1:


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}" />

Result:

 [echo] business
 [echo] web

BUILD SUCCESSFUL

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.



来源:https://stackoverflow.com/questions/6287655/ant-equivalent-of-cut-sort-uniq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!