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

时间:2021-01-29 12:15:25

In windows 2008, we have multiple files in a directory. The files are having paths as contents and those texts should be replaced with other string.Find example below:

在Windows 2008中,我们在目录中有多个文件。这些文件的路径为内容,这些文本应替换为其他字符串。查看下面的示例:

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.

但目前的要求似乎使用正则表达式,我无法找到解决方案。

1 个解决方案

#1


1  

Just replace etc\ followed by anything up to a \ again with just exe:

只需用exe替换etc \后跟任何东西再到\:

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

#1


1  

Just replace etc\ followed by anything up to a \ again with just exe:

只需用exe替换etc \后跟任何东西再到\:

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