【发布时间】:2016-04-05 09:43:33
【问题描述】:
所以,我得到了文本文件,它基本上包含键/值行,每一行都用空格分隔。 我正在尝试实现的是按键提取价值,例如。在 shell 中是这样完成的:
cat textfile|awk '/item1/ {print $2}'
在 groovy 中,类似的东西会做这样的事情:
aa = """
item1 /first/path
item2 /another/path
"""
aa.eachLine {
m = it =~ /item1\s+(.*)/
if (m.matches()) {
println m.group(1)
}
}
但是,问题是:如何以更好/更 Groovy 的方式做到这一点?
问候,Wojtek
【问题讨论】: