Groovy:读取数组中文件的内容并进行grep读取 [英] Groovy: Read contents of a file in an array and grep for something

查看:208
本文介绍了Groovy:读取数组中文件的内容并进行grep读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在GROOVY脚本中实现以下内容,但出现错误: 读取数组中HTML文件的内容,然后读取grep该数组中的内容.

I am trying to implement following in GROOVY script but getting errors: Read contents of an HTML file in an array and then grep for something in that array.

def file1 = new File("/path/to/the/file/xyz.html");
def lines = file1.readLines()
if ((-e "/path/to/the/file/xyz.html") and (!(grep /jira.bugtracker.com/, lines))
{
    println (" the changes are present\n");
    exit 0;
}
else
{
    println (" the changes are not present\n");
    exit 1;
}

请查看代码并提出正确的方法.

Please review the code and suggest the correct method.

推荐答案

您可以尝试这样.

if ( new File("/path/to/the/file/xyz.html").text?.contains("jira.bugtracker.com")){
   println (" the changes are present\n");
} else {
   println (" the changes are not present\n");
}

这篇关于Groovy:读取数组中文件的内容并进行grep读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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