我有一个JSON数据文件,它们都在一行上。 JSON有一些我需要更新的文件路径。这是一个样本。
"diffuseTexture":{"name":"Axe_03_diffuse.png","level":1.0,"hasAlpha":false,"getAlphaFromRGB":false,"coordinatesMode":0,"isCube":false,"uOffset":0.0,"vOffset":0.0,"uScale":1.0,"vScale":1.0,"uAng":0.0,"vAng":0.0,"wAng":0.0,"wrapU":1,"wrapV":1,"coordinatesIndex":0,"isRenderTarget":false,"renderTargetSize":0,"mirrorPlane":null,"renderList":null,"animations":[]},"diffuseFresnelParameters":null,"ambientTexture":null,"opacityTexture":null,"opacityFresnelParameters":null,"reflectionTexture":null,"reflectionFresnelParameters":null,"emissiveTexture":null,"emissiveFresnelParameters":null,"specularTexture":null,"bumpTexture":null},{"name":"hammer01","id":"dd00d71c-5865-4574-9437-e2777fef63f0","backFaceCulling":true,"wireframe":false,"ambient":[0.588,0.588,0.588],"diffuse":[1.0,1.0,1.0],"specular":[0.0,0.0,0.0],"emissive":[0.0,0.0,0.0],"specularPower":25.6,"alpha":1.0,"diffuseTexture":{"name":"Hammer_01_diffuse.png","level":1.0,"hasAlpha":false,"getAlphaFromRGB":false,"coordinatesMode":0,"isCube":false,"uOffset":0.0,"vOffset":0.0,"uScale":1.0,"vScale":1.0,"uAng":0.0,"vAng":0.0,"wAng":0.0,"wrapU":1,"wrapV":1,"coordinatesIndex":0,"isRenderTarget":false,"renderTargetSize":0,"mirrorPlane":null,"renderList":null,"animations":[]},"diffuseFresnelParameters":null,"ambientTexture":null,"opacityTexture":null,"opacityFresnelParameters":null,"reflectionTexture":null,"reflectionFresnelParameters":null,"emissiveTexture":null,"emissiveFresnelParameters":null,"specularTexture":null,"bumpTexture":null},{"name":"hammer02","id":"ecfa63fb-6939-4ca6-932c-4413693731dc","backFaceCulling":true,"wireframe":false,"ambient":[0.588,0.588,0.588],"diffuse":[1.0,1.0,1.0],"specular":[0.0,0.0,0.0],"emissive":[0.0,0.0,0.0],"specularPower":25.6,"alpha":1.0,"diffuseTexture":{"name":"Hammer_02_diffuse.png",
我正在尝试更新的部分数据是.png
引用
我想为它们添加另一个路径,因此Axe_03_diffuse.png
将成为/assets/babylon/Axe_03_diffuse.png
我在执行替换时遇到问题,因为文件输入全部在一行上。外卡匹配器已匹配整个输入并且没有正确破坏。
我一直在尝试不同的排列:
cat ./hero.babylon | sed -E "s/(\"diffuseTexture\"\:\{\"name\"\:\")(..*)\.png/\1\/assets\/babylon\/\2/g"
这适用于(..*
)外卡组。
答案 0 :(得分:1)
您可以尝试以下sed命令。
sed -r 's~(\"diffuseTexture\"\:\{\"name\"\:\")([^\"]*\.png)\"~\1/assets/babylon/\2"~g' file
[^"]*
匹配任何字符,但不匹配双引号,零次或多次。
答案 1 :(得分:0)
我想,这可能会有所帮助:
sed -r 's|"name":"([^"]*.png)|"name":"/path/to/prefix/\1|g' test.json
由于您已经知道sed
,我不会想到,需要做出很多解释。