[英]Is there an API for grep, pipe, cat in groovy?
在groovy中有grep,pipe,cat的API吗?
Not sure I understand your question. 不确定我理解你的问题。
Do you mean make system calls and pipe the results? 你的意思是进行系统调用并管道结果吗?
If so, you can just do something like: 如果是这样,您可以执行以下操作:
println 'cat /Users/tim_yates/.bash_profile'.execute().text
To print the contents of a file 打印文件的内容
You can pipe process output as well: 您也可以管道进程输出:
def proc = 'cat /Users/tim_yates/.bash_profile'.execute() | 'grep git'.execute()
println proc.text
If you want to get the text of a File
using standard Groovy API calls, you can do: 如果要使用标准Groovy API调用获取
File
的文本,可以执行以下操作:
println new File( '/Users/tim_yates/.bash_profile' ).text
And this gets a list of the lines in a file, finds all that contain the word git
then prints each one out in turn: 这将获取文件中的行列表,找到包含单词
git
所有行,然后依次打印每个行:
new File( '/Users/tim_yates/.bash_profile' ).text.tokenize( '\n' ).findAll {
it.contains 'git'
}.each {
println it
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.