windows-7 - 在Windows 7中使用find和sed递归修改文件

标签 windows-7 powershell replace sed find

我尝试在 Windows 7 中使用 find 和 GNU sed 来递归地替换跨多个目录的多个文件中的一行文本。我看了this question但 PowerShell 解决方案似乎只能处理一个文件,而我想从当前目录递归地处理具有特定扩展名的所有文件。我尝试了这个命令:

find "*.mako" -exec sed -i "s:<%inherit file="layout.mako"/>:<%inherit file="../layout.mako"/>:"

但这给了我一堆废话,并且没有改变任何文件:

---------- EDIT.MAKO

File not found - -EXEC
File not found - SED
File not found - -I
File not found - LAYOUT.MAKO/>:<%INHERIT FILE=../LAYOUT.MAKO/>:

我该怎么做?看来我应该安装我需要的所有工具,而不必安装 Cygwin 或 UnixUtils 或其他任何东西。

编辑:好吧,使用 GNU find 工作,我仍然无法到达任何地方,因为我无法让 find 部分工作:

> gfind -iname "*.mako" .
C:\Program Files (x86)\GnuWin32\bin\gfind.exe: paths must precede expression
> gfind . -iname "*.mako"
C:\Program Files (x86)\GnuWin32\bin\gfind.exe: paths must precede expression
> gfind -iname "*.mako" .
C:\Program Files (x86)\GnuWin32\bin\gfind.exe: paths must precede expression

我最初没有在 Windows 7 中使用 GNU find,因为 this question .

编辑:

我尝试了以下操作,但 sed 没有通过这种方式看到任何输入文件:

> ls -r | grep mako | sed -i 's/file="layout.mako"/file="..\/layout.mako"/'
sed.exe: no input files

最佳答案

正在从 Windows 查找 FIND,而不是从 GNU 查找。

因此,将您的 find.exe(从 gnu)重命名为 gfind.exe(例如),然后在您希望运行它时调用 gfind 而不是 find。

[编辑]
gfind 。 -name "*.mako" (不是 gfind -iname "*.make"。)
[/编辑]

关于windows-7 - 在Windows 7中使用find和sed递归修改文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6764194/

相关文章:

Python 返回 "wrong"退出代码

powershell - here-string,powershell 中的变量扩展

r - 如果在 R 中模拟后使用鼠标滚轮,Windows 7 将变得无响应

powershell:导入模块时运行代码

powershell - 抑制 powershell 输出消息

javascript - 正则表达式 : multiple occurences of a word, 仅替换最后一次出现的位置

regex - 用 sed 替换字符串

javascript - Dojo lang.replace - 如何提供默认值,而不是 'undefined' ?

c# - 将输入从类似键盘的设备重定向到 Windows 环境中的后台进程

asp.net - Windows7 上的 SMTP 服务