[英]Bash sed string substitution error
我有一個json文件,其中包含以下示例:
"images": [
".images/phones/motorola-xoom.0.jpg",
".images/phones/motorola-xoom.1.jpg",
".images/phones/motorola-xoom.2.jpg"
],
我正在Windows和sed上使用git bash嘗試用./images
替換.images
。 我想到了使用sed -i 's/.images/.\\/images/g' filename.json
但是在執行sed時,sed sed -i 's/.images/.\\/images/g' filename.json
選擇並替換“ images”的第一個實例。 為什么會這樣,我應該如何修改sed命令的文件? 謝謝
轉義點.
。 作為.
意味着“任何東西”,您必須先將其轉義以使它表示正義.
:
$ 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"
],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.