"sed: '/' 불일치" 오류 수정 방법

"sed: '/' 불일치" 오류 수정 방법

Jenkins에서 실행될 Groovy 스크립트에서 다음 명령을 실행하고 싶습니다.

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'

답변1

목록을 실행하는 것이 단일 문자열을 실행하는 것보다 훨씬 낫습니다.

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=123

관련 정보