簡體   English   中英

在groovy中有grep,pipe,cat的API嗎?

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

在groovy中有grep,pipe,cat的API嗎?

不確定我理解你的問題。

你的意思是進行系統調用並管道結果嗎?

如果是這樣,您可以執行以下操作:

println 'cat /Users/tim_yates/.bash_profile'.execute().text

打印文件的內容

您也可以管道進程輸出:

def proc = 'cat /Users/tim_yates/.bash_profile'.execute() | 'grep git'.execute()
println proc.text

如果要使用標准Groovy API調用獲取File的文本,可以執行以下操作:

println new File( '/Users/tim_yates/.bash_profile' ).text

這將獲取文件中的行列表,找到包含單詞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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM