grep, sed 또는 awk를 사용하여 컬 출력에서 ​​특수 문자를 제거하는 방법

grep, sed 또는 awk를 사용하여 컬 출력에서 ​​특수 문자를 제거하는 방법

\r\n컬 출력에서 ​​제거 하려는 코드는 다음과 같습니다.

curl -s -u ian.guinto:W0lfg@ng131994 --request GET --url 'https://jira.toro.io/rest/api/2/issue/OJTSYSAD-829/comment' -H "Content-Type: application/json" | jsonpp | grep body | cut -d ':' -f2 

출력됩니다.

 "Test comment",
 "test comment 2\r\n",
 "test comment3\r\nTest comment 4\r\n",

내 예상 결과는 다음과 같습니다

 "Test comment",
 "test comment 2",
 "test comment3 Test comment 4",

답변1

실제로 JQ를 사용하여 이 작업을 수행할 수 있습니다.

$ curl -L -O -u ian.guinto:W0lfg@ng131994 \
jira.toro.io/rest/api/2/issue/OJTSYSAD-829/comment

$ jq '.comments[].body | rtrimstr("\r\n") | gsub("\r\n"; " ")' comment
"Test comment"
"test comment 2"
"test comment3 Test comment 4"

http://github.com/stedolan/jq

관련 정보