Shell 用于搜索字符串并将其存储在文件中的脚本

Shell script for searching a string and store it in a file

我有一个 JSON JIRA 问题的响应文件。我需要从中提取 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-#作为另一个脚本的变量

简单的 grep 版本可能如下所示:

grep -oE "\"key\":\"CIJ-[0-9]*\"" data.txt | awk -F':' '{print }'