使用 ant,检查或比较文件中列出的所有项目出现在另一个文件或列表中 [英] Using ant, check or compare all items listed in a file appear in another file or list

查看:22
本文介绍了使用 ant,检查或比较文件中列出的所有项目出现在另一个文件或列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道您是否可以提供帮助.我是蚂蚁脚本的新手.

I was wondering if you could help. I am new to ant scripting.

我希望能够比较两个列表.File1.txt 将包含大量参数的列表,而 file2.txt 将仅包含这些参数的一部分.

I want to be able to compare two lists. File1.txt will contain a list of a lot of parameters and file2.txt will only contain a section of those parameters.

文件 1.txt

dbipAddress=192.168.175.130
QAGENT_QCF=AGENT_QCF
QADJUST_INVENTORY_Q=ADJUST_INVENTORY_Q
QCREATE_ORDER_Q=CREATE_ORDER_Q
QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q

File2.txt

AGENT_QCF
ADJUST_INVENTORY_Q
CREATE_ORDER_Q

我想知道file1.txt中的所有Q都包含在file2.txt中,在'='之后,如果它们不是那么蚂蚁脚本将停止并显示一条Echo消息,如果它们然后脚本将移动到下一个.

I want to know that all the Qs in file1.txt are contained in file2.txt, after the '=', if they aren't then the ant script will stop and an Echo message will be displayed if they are then the script will move to the next .

因此在上面的示例中,脚本将停止,因为它不包含以下 Q;QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q.

So in the example above the script will stop as it does not contain the following Q; QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q.

推荐答案

ANT 不是一种编程语言,所以我认为您需要嵌入一个.

ANT is not a programming language, so I think you need to embed one.

以下示例使用 Groovy:

<project name="demo" default="check">

    <target name="bootstrap">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/groovy.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.3/groovy-all-2.1.3.jar"/>
    </target>

    <target name="check">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
        <groovy>
            def props = new Properties()
            new File("File1.txt").withInputStream { stream -> props.load(stream) }
            def requiredValues = new File("File2.txt").text.split()

            requiredValues.each { check ->
                if (! props.find{it.value == check}) {
                    ant.fail "Cannot find ${check} in File1.txt"
                }
            }
        </groovy>
    </target>

</project>

这篇关于使用 ant,检查或比较文件中列出的所有项目出现在另一个文件或列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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