curl 和 jq 替换值中的子字符串
Curl and jq replace substring in value
使用 curl 我从 github api:
得到 json
curl https://api.github.com/repos/angular/angular/pulls?label=comp%3A+zones&state=closed&page=1&per_page=5
结果:
[
{
"url": "https://api.github.com/repos/angular/angular/pulls/33703",
"id": 338899730,
"node_id": "MDExOlB1bGxSZXF1ZXN0MzM4ODk5NzMw",
"html_url": "https://github.com/angular/angular/pull/33703",
"diff_url": "https://github.com/angular/angular/pull/33703.diff",
"patch_url": "https://github.com/angular/angular/pull/33703.patch",
"issue_url": "https://api.github.com/repos/angular/angular/issues/33703",
"number": 33703,
"state": "closed",
"locked": false,
"title": "add AOT mode default to version 9 upgrade doc",
[...]
与 jq :
$ curl 'https://api.github.com/repos/angular/angular/pulls?label=comp%3A+zones&state=closed&page=1&per_page=2' | jq --raw-output '.[] | "\(.id) \(.title)"'
我可以很好地将其格式化为
338899730 add AOT mode default to version 9 upgrade doc
338868666 update jiali's info on collaborator page of angular.io
如何在输出前从标题值中删除 add
和 update
?
使用sub
,例如:
.[]
| "\(.id) \(.title|sub("^(add|update) *";""))"
使用 curl 我从 github api:
得到 jsoncurl https://api.github.com/repos/angular/angular/pulls?label=comp%3A+zones&state=closed&page=1&per_page=5
结果:
[
{
"url": "https://api.github.com/repos/angular/angular/pulls/33703",
"id": 338899730,
"node_id": "MDExOlB1bGxSZXF1ZXN0MzM4ODk5NzMw",
"html_url": "https://github.com/angular/angular/pull/33703",
"diff_url": "https://github.com/angular/angular/pull/33703.diff",
"patch_url": "https://github.com/angular/angular/pull/33703.patch",
"issue_url": "https://api.github.com/repos/angular/angular/issues/33703",
"number": 33703,
"state": "closed",
"locked": false,
"title": "add AOT mode default to version 9 upgrade doc",
[...]
与 jq :
$ curl 'https://api.github.com/repos/angular/angular/pulls?label=comp%3A+zones&state=closed&page=1&per_page=2' | jq --raw-output '.[] | "\(.id) \(.title)"'
我可以很好地将其格式化为
338899730 add AOT mode default to version 9 upgrade doc
338868666 update jiali's info on collaborator page of angular.io
如何在输出前从标题值中删除 add
和 update
?
使用sub
,例如:
.[]
| "\(.id) \(.title|sub("^(add|update) *";""))"