![](/img/trans.png)
[英]grep 'post_content' while parsing with cat & pipe into 'post_name'.html
[英]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.