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

おすすめ記事