Regex Bash sed字符串替换错误
我有一个json文件,其中包含以下内容,例如:Regex Bash sed字符串替换错误,regex,json,bash,sed,git-bash,Regex,Json,Bash,Sed,Git Bash,我有一个json文件,其中包含以下内容,例如: "images": [ ".images/phones/motorola-xoom.0.jpg", ".images/phones/motorola-xoom.1.jpg", ".images/phones/motorola-xoom.2.jpg" ], 在Windows和sed上使用gitbash,我试图用/images替换.images。 我曾想过使用sed-I's/.images/\/images/g'filen
"images": [
".images/phones/motorola-xoom.0.jpg",
".images/phones/motorola-xoom.1.jpg",
".images/phones/motorola-xoom.2.jpg"
],
在Windows和sed上使用gitbash,我试图用/images
替换.images
。
我曾想过使用sed-I's/.images/\/images/g'filename.json
,但在这样做时,sed也会选择并替换“images”的第一个实例。为什么会这样?我应该如何修改我的sed命令?
Thx逃逸dot
。由于
表示“任何东西”,您必须将其转义,使其仅表示
:
$ sed 's/\.images/.\/images/g' file
"images": [
"./images/phones/motorola-xoom.0.jpg",
"./images/phones/motorola-xoom.1.jpg",
"./images/phones/motorola-xoom.2.jpg"
],
是正则表达式元字符,需要在模式字符串中转义它