开发者

Is there an API for grep, pipe, cat in groovy?

Is there an API for grep, pipe, ca开发者_运维技巧t in groovy?


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:

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:

new File( '/Users/tim_yates/.bash_profile' ).text.tokenize( '\n' ).findAll {
  it.contains 'git'
}.each {
  println it
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜