如何使用awk解析JSON输出的某些内容?

时间:2018-11-06 06:25:08

标签: shell parsing awk scripting gerrit

我有一个场景,我要从查询中提取Gerrit数据,但现在想从中提取一些特定数据。

 ssh -p 29418 gerrit.abc.se gerrit query --format=JSON project:abc status:merged branch:master change:Ie2ef9e --all-reviewers > reviewers.txt

  Output of above command:

   {"project":"dddd","branch":"master","id":"Ie2ef9e47fc6c046091d93521198bf0a1075cb77e",
    "number":3984134,"subject":"adding configuration","owner":{"name":"aaaaa",
    "email":"abc.com","username":"eeeee"},"url":"https://gerrit.abc.se/3984134",
    "commitMessage":"adding configuration\n\nChange-Id: Ie2ef9e47fc6c046091d93521198bf0a1075cb77e\n",
    "createdOn":1533208993,"lastUpdated":1536301464,"open":false,
    "status":"MERGED",
    "allReviewers":[{"name":"aabcc","email":"abc.coom",
    "username":"eeeee"},{"name":"ADP Automation","username":"adpauto"}]}

现在我要提取的是allReviwers名称-

 allReviewers
 name: aabcc
 name: ADP Automation

我该怎么做?只需提取审阅者的姓名,然后将其存储在某些csv文件中即可。我必须为每个Gerrit更改运行。 我正在尝试使用awk,但无法提取。请提出建议。

0 个答案:

没有答案