首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Groovy:读取数组和grep中的文件内容

Groovy:读取数组和grep中的文件内容
EN

Stack Overflow用户
提问于 2017-05-23 19:10:40
回答 2查看 10.2K关注 0票数 1

我试图在GROOVY脚本中实现以下内容,但得到了错误:读取数组中的HTML文件的内容,然后对该数组中的内容执行grep

代码语言:javascript
运行
复制
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;
}

请检查代码并建议正确的方法。

EN

回答 2

Stack Overflow用户

发布于 2017-05-23 20:43:36

代码语言:javascript
运行
复制
def file1 = new File("/path/to/the/file/xyz.html" )
def lines = file1.readLines()
def found = lines.find{ line-> line =~ /jira.bugtracker.com/ }
println ("the changes are ${ found ? '' : 'not ' }present")
return found ? 0 : 1
票数 3
EN

Stack Overflow用户

发布于 2017-05-23 22:59:16

你可以试着这样做。

代码语言:javascript
运行
复制
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");
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44133158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档