开发者

Ant equivalent of cut | sort | uniq

开发者 https://www.devze.com 2023-03-11 05:16 出处:网络
In an Ant task I set a property which is a list of files. e.g. web/src/main/test/com/whatever/Ralph开发者_运维问答

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消