Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sed command to change value in .spec file

How to change a value in .spec file using sed. Want to change the $nmatch value of build to someother value say build1.1

{
"files": [
  {
    "aql": {
    "items.find": {
    "repo": {"$eq":"app-java-repo"},
    "path": "archives/test/app",
    "type": "folder",
    "$or": [
          {
            "$and": [
              {
                "name": {"$nmatch" : "*build*"} //change value using sed
              }
            ]
          }
        ]
      }
    }
  }
]
}

Tried below command but not working

sed -i -e '/name:/{s/\($nmatch\).*/\1: "'"build1.1"'" /}'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You document format is json, so you should use jq for editing:

jq '.files[0].aql."items.find"."$or"[0]."$and"[0].name."$nmatch"="build1.1"' spec

With sed, you can’t reliably access the correct name node. Your code doesn’t work because you didn’t include the quotes around name in your search pattern. Using sed would be ok if you have a unique identifier for build. Example:

sed -i 's/BUILD_NUMBER/build1.1/g' spec
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading