我有一个JIRA问题的JSON响应文件。我需要从中提取JIRA问题密钥并将其存储在变量中。以下是JIRA问题密钥 CIJ-4
的示例响应文件{"expand":"schema,names","startAt":0,"maxResults":50,"total":2,"issues":[{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"10100","self":"http://localhost:7080/rest/api/2/issue/10100","key":"CIJ-4","fields":{"issuetype":{"self":"http://localhost:7080/rest/api/2/issuetype/1","id":"1","description":"A problem which impairs or prevents the functions of the product.","iconUrl":"http://localhost:7080/images/icons/issuetypes/bug.png","name":"Bug","subtask":false},"components":[],"timespent":null,"timeoriginalestimate":null,"description":"Creating an issue via REST API","project":{"self":"http://localhost:7080/rest/api/2/project/10000","id":"10000","key":"CIJ","name":"CIJIRA","avatarUrls":{"48x48":"http://localhost:7080/secure/projectavatar?avatarId=10011","24x24":"http://localhost:7080/secure/projectavatar?size=small&avatarId=10011","16x16":"http://localhost:7080/secure/projectavatar?size=xsmall&avatarId=10011","32x32":"http://localhost:7080/secure/projectavatar?size=medium&avatarId=10011"}},"fixVersions":
在我的示例中,请求是CIJ-4,但是当记录新请求时,数字会增加 CIJ-10,CIJ-100,CIJ-1000 。所以我的挑战是如何提取确切的JIRA问题密钥?
在我提取结果并将其存储在一个文件中后,比如说result.txt,我需要解析reuslt.txt,每次有CIJ-#时,我需要将CIJ-#作为变量传递给另一个脚本
答案 0 :(得分:1)
简单的grep版本可能如下:
grep -oE "\"key\":\"CIJ-[0-9]*\"" data.txt | awk -F':' '{print $2}'