sed-i bash命令修改JSON上的行my文件(末尾的erase.png)



我正试图找到一种擦除"的方法;。png";该JSON文件中的扩展名,但仅用于属性(因此"image":"test.png"应该保留.png和"uri":"0.png"也应该保留它(

但是所有的属性值最后都应该没有.png,所以背景的值应该是Yellow.png而不是Yellow.png

有什么建议吗?我试着使用sed命令,比如:

sed -i 's/Yellow.png/Yellow/g' myfile.json

它不起作用,也不是最好的方法,因为我必须手工完成每个属性。。。(我放了一个样本,但我有100多个属性(

{
"name": "test",
"symbol": "test",
"image": "test.png",
"properties": {
"files": [
{
"uri": "0.png",
"type": "image/png"
}
],
"category": "image",
"creators": []
},
"description": "test",
"seller_fee_basis_points": 0,
"attributes": [
{
"trait_type": "Head",
"value": "1.png"
},
{
"trait_type": "Body",
"value": "Big.png"
},
{
"trait_type": "Left Arm",
"value": "Gun.png"
},
{
"trait_type": "Right Arm",
"value": "Gun.png"
},
{
"trait_type": "Left Legs",
"value": "Normal.png"
},
{
"trait_type": "Background",
"value": "Yellow.png"
},
{
"trait_type": "Right Legs",
"value": "Normal.png"
}
],
"collection": {
"name": "Test",
"family": "test"
}

}

如果只想更改"value"之后的内容,可以使用sed执行以下操作:

's/("value".*).png"/1"/'

CCD_ 2匹配以"value"开始并以.png"结束的任何内容。

然后1"将其替换为第一个匹配组(括号之间的内容(和一个双引号。

您可以在此处看到结果:https://sed.js.org/?gist=9f1a0ce59fd9a7b46277498cc106444e

最新更新