简体   繁体   English

目录中所有文件中的文本替换

[英]Text replacement in all the files in a directory

In windows 2008, we have multiple files in a directory.在 Windows 2008 中,我们在一个目录中有多个文件。 The files are having paths as contents and those texts should be replaced with other string.Find example below:文件以路径为内容,这些文本应替换为其他字符串。查找下面的示例:

The files are having the paths like:这些文件的路径如下:

File1:文件1:

C:\\Apps\\ etc\\A1 \\X.exe should be replaced with C:\\Apps\\ exe \\X.exe C:\\Apps\\ etc\\A1 \\X.exe 应替换为 C:\\Apps\\ exe \\X.exe

File2:文件2:

C:\\Apps\\ etc\\B1 \\Y.exe should be replaced with C:\\Apps\\ exe \\Y.exe C:\\Apps\\ etc\\B1 \\Y.exe 应该替换为 C:\\Apps\\ exe \\Y.exe

I am trying to find a single command which will replace the bold lettered strings as mentioned above.我试图找到一个命令来替换上面提到的粗体字母字符串。

In case of normal strings I use the below command and it works:在正常字符串的情况下,我使用以下命令并且它有效:

perl -i.bak -pe "BEGIN{@ARGV = map glob, @ARGV} s/string1/string2/g" ./*.txt 

But the current requirement seems to use regular expression for which I am not able to find a solution.但是当前的要求似乎使用正则表达式,我无法找到解决方案。

只需用 exe 替换 etc\\ 后跟任何直到 \\ 的内容:

's/etc\\[^\\]*\\/exe\\/g'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM