Skip to content
Advertisement

Need help in regular expression using sed

I have following code:-

test -z "$(echo ${JIRA_DETAIL} | jq '.fields.status.name' | sed -r "s/"(Done|Completed|Closed)"//")" && echo "Found valid Jira" || echo "Not a valid Jira (Closed/Completed/Done)" 

The code works. When the status is one of the among (done, completed or closed) then it prints “Found valid Jira”. I want the "Not In" condition of it i.e. whenever the status comes out to be any of these then it should say “Found valid Jira”.

Jira details response that I get is as follows:-

{
   "expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
   "id":"10000",
   "self":"https://mycloudbox.atlassian.net/rest/api/2/issue/10000",
   "key":"MYC-1",
   "fields":{
      "status":{
         "self":"https://mycloudbox.atlassian.net/rest/api/2/status/3",
         "description":"This issue is being actively worked on at the moment by the assignee.",
         "iconUrl":"https://mycloudbox.atlassian.net/images/icons/statuses/inprogress.png",
         "name":"In Progress",
         "id":"3",
         "statusCategory":{
            "self":"https://mycloudbox.atlassian.net/rest/api/2/statuscategory/4",
            "id":4,
            "key":"indeterminate",
            "colorName":"yellow",
            "name":"In Progress"
         }
      }
   }
}

I tried going through with docs but it is confusing. I’m not good in regex hence checking. How to put ^ or Not In condition on this?

[Updated defective Code using Linux If-Else] It is going every time in else condition and printing Valid JIRA Id found!. Pls suggest as I want to try out using Linux If-Else only, thanks

- |
      if [[ "$JIRA_STATUS" == "^(Done|Completed|Closed)$" ]] 
       then 
         echo "Invalid JIRA (Done/Completed/Closed) found!"
         exit 1
       else echo "Valid JIRA Id found!" 
      fi 

Advertisement

Answer

Thanks everyone for guiding me.

I’m finally able to resolve this issue by modifying the code like below:-

- |
      if test -z "$(echo ${JIRA_STATUS} | sed -r "s/"(Done|Completed|Closed)"//")" 
        then 
          echo "Not a valid Jira (Done/Completed/Closed)"; exit 1
        else 
          echo "Valid Jira found!"; echo $?
      fi

I had used the test command along with if-else condition in Linux to make it work

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement