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"'" /}'
CodePudding user response:
Your 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
CodePudding user response:
A more "indirect" way is to simply set everything with $nmatch
:
jq '(.. | select(has("$nmatch"))? ) = "build1.1"' input.json