在Windows中搜索和替换

在Windows中搜索和替换

本文介绍了Strawberry Perl-在Windows中搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下命令:

I am trying to execute the following command:

perl -pi -e 's,vaadin-element,color-picker,g' *.* demo/* test/* src/* theme/*/*
(遵循文档)

perl -pi -e 's,vaadin-element,color-picker,g' *.* demo/* test/* src/* theme/*/*
(following this document)

不幸的是,我使用的Pearl的窗口分布似乎与该命令存在一些问题,因为出现以下错误:

Unfortunately it seems that the window distribution of pearl I use has some issues with the command, as I get the following error:

Can't open *.*: Invalid argument.
Can't open demo/*: Invalid argument.
Can't open test/*: Invalid argument.
Can't open src/*: Invalid argument.
Can't open theme/*/*: Invalid argument.

关于如何解决该问题的任何建议?预先谢谢你!

Any suggestions on how to fix that?Thank you in advance!

免责声明::我以前从未使用过Pearl,而且绝对没有经验.

Disclaimer: I never used pearl before and have absolutely no experience.

推荐答案

在unix系统中,shell扩展glob并将文件名传递给程序.

In unix systems, the shell expands globs and passes the file names to the program.

$ perl -e'CORE::say for @ARGV' *
file1
file2

另一方面,Windows外壳程序按原样传递值,然后将其留给程序以将它们视为glob(如果需要).

The Windows shell, on the other hand, passes the values as is, and leaves it up to the program to treat them as globs if so desired.

>perl -e"CORE::say for @ARGV" *
*

您可以按照以下步骤进行通配:

You can perform the globbing as follows:

>perl -MFile::DosGlob=glob -e"BEGIN { @ARGV = map glob, @ARGV } CORE::say for @ARGV" *
file1
file2

通常不需要BEGIN块,但是使用-n(由-p隐含)时,它将确保一次足够早的定位.

The BEGIN block isn't generally needed, but it will ensure the globing once and early enough when using -n (which is implied by -p).

-MFile::DosGlob=glob使glob具有类似Windows的语义.例如,它会导致*.*匹配所有文件,即使它们不包含..

The -MFile::DosGlob=glob makes glob have Windows-like semantics. For example, it causes *.* to match all files, even if they don't contain ..

集成:

perl -i -MFile::DosGlob=glob -pe"BEGIN { @ARGV = map glob, @ARGV } s,vaadin-element,color-picker,g" *.* demo/* test/* src/* theme/*/*

这篇关于Strawberry Perl-在Windows中搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:27