

























偶尔的替换用 VSCode 或 JetBrains IDE 的类似 Cmd + Shift + H 的文件替换就可以了。
经常或快捷的使用,可以用 grep + sed 命令进行替换。
搜索试了几个命令,发现有空格的路径会导致一些错误。
一顿搜索,找到了一个解决办法,参考 Grep word within a file then copy the file:
--null 告诉 grep 以 NUL 字符分割文件名-0 告诉 sed 以 NUL 分割输入最终命令示例,以 bar 替换 foo。
区分大小写:
$ grep -lr --null 'foo' * | xargs -0 sed -i '' 's/foo/bar/g'
不区分大小写:
$ grep -ilr --null 'foo' * | xargs -0 sed -i '' 's/foo/bar/gI'
grep
-i, --ignore-case 查找文件时不区分大小写-l, --files-with-matches 返回文件名-R, -r, --recursive 递归搜索子目录sed
-i 默认 sed 会打印到标准输出,使用 -i 将直接在文件内编辑替换s 替换g 全局替换标志I 大小写不敏感标志示例。
替换需求:
- 
+ 
可能有需要转义的:
查找的字符串、替换的内容:
](/img
](https://example.com/img
转义后:
](\/img
https:\/\/example.com\/img
将转义后的内容代入就可以了,完整的:
$ grep -lr --null '](\/img' | xargs -0 sed -i '' 's/](\/img/](https:\/\/example.com\/img/g'
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。