【问题标题】:Command line "find" piped to sed on Windows not working在 Windows 上通过管道“查找”到 sed 的命令行“查找”不起作用
【发布时间】:2017-12-13 15:11:27
【问题描述】:

我正在构建一个使用 Angular Material 设计包的网站。最近一次更新后,该包更改了许多 CSS 样式类的名称,从而破坏了旧代码。该软件包提供了一个命令,可以运行该命令以用新名称 (source) 替换 .css.scss 文件中的所有旧名称实例:

find . -type f -name "*.scss" -o -name "*.css"| xargs sed -i 's/\.md-/\.mat-/g'

我认为这是为了将项目目录和子目录中的样式文件中的所有.md- 替换为.mat-。在确保我可以在我的 Windows 机器上运行 findxargs 之后,我尝试运行该命令。这是我得到的:

C:\project>find . -type f -name "*.scss" -o -name "*.css"| xargs sed -i 's/\.md-/\.mat-/g'
File not found - "*.css"
sed: no input files

C:\project>find . -type f -name "*.scss"| xargs sed -i 's/\.md-/\.mat-/g'
Access denied - .
File not found - -TYPE
File not found - F
File not found - -NAME
sed: no input files

以管理员身份运行没有任何区别。我不知道从这里去哪里。怎么了?在 Windows 7 上是否有其他方法可以做到这一点?

【问题讨论】:

  • Windows find 是一个与 *nix find 截然不同的应用程序/命令。
  • 在命令提示符下键入 find /? 会显示 Windows find 不接受任何这些参数,这强烈表明您没有运行 Windows 版本的文件。联系给你命令的人,并要求他们为你的操作系统提供正确的版本。
  • @zwer 谢谢!这使我找到了正确的答案。如果没有其他人写,我会写下来。

标签: windows sed command-line


【解决方案1】:

如果您的 Windows 系统上有正确的xargssed,您可以尝试使用dir 而不是find,例如:

dir /b /s *.*css | xargs sed -i 's/\.md-/\.mat-/g'

【讨论】:

  • 我还有一些.scss文件要处理
  • @BeetleJuice - 这应该同时选择 .css.scss 文件,但如果您想明确指定它们:dir /b /s *.css /s *.scss | xargs sed -i 's/\.md-/\.mat-/g'
  • 我在阅读您的评论后大约 2 分钟通过使用正确的 find 程序解决了它(Linux 等效项可以在 /path/to/git/usr/bin 中找到,所以我没有尝试您的方法(如果我测试一下,我会回来选择你的答案)。+1 的帮助;你让我来解决我的问题。
猜你喜欢
  • 2012-03-19
  • 2012-06-26
  • 2011-08-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-23
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
相关资源
最近更新 更多