我想在groovy脚本上运行以下命令,然后运行在Jenkins上:
def sedCmd = cat sample.txt | sed -n -e /word id=123/,/end id = 123/ p
def logs = sedCmd.execute()文件"sample.txt“如下所示:
Thurs 20 Sep 2018 word id=123
The cat
In the hat
Bla bla
Thurs 20 Sep 2018 end id=123
Test当我运行该命令时,会得到以下错误:
sed: unmatched '/'我在我的终端上本地测试了相同的命令,做了一些小改动,它的工作原理如下:
cat sample.txt | sed -n -e '/word id=123/,/end id = 123/ p'发布于 2018-09-20 20:24:25
执行一个列表比执行一个字符串要幸运得多:
def sedCmd = ["sed", "-n", "/word id=123/,/end id=123/ p", "sample.txt"]
def process = sedCmd.execute()
process.waitFor()
process.err.readLines().each {line -> println "Err: $line"}
process.in.readLines().each {line -> println "Out: $line"}Out: Thurs 20 Sep 2018 word id=123
Out: The cat
Out: In the hat
Out: Bla bla
Out: Thurs 20 Sep 2018 end id=123https://unix.stackexchange.com/questions/470302
复制相似问题