使用Perl代码对多个.txt文件应用多个查找和替换正则表达式查询 [英] Apply multiple find and replace regex queries on multiple .txt files using a Perl code

查看:56
本文介绍了使用Perl代码对多个.txt文件应用多个查找和替换正则表达式查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows代码上找到一个Perl,使我能够对特定目录中的多个文件应用多个查找和替换正则表达式查询.我可以使用许多文本编辑器(例如UltraEdit)来应用多个查找和替换正则表达式查询.

I'm trying to find a Perl on Windows code that enables me to apply multiple find and replace regex queries on multiple files in a specific directory. I'm able to apply multiple find and replace regex queries using many text editors (for example UltraEdit).

推荐答案

您的问题不是很具描述性.这是您想要的吗?

Your question isn't very descriptive. Does this do what you want?

已编辑为可在Windows上使用

Edited to work on Windows

perl -i.bak -pe"BEGIN {@ARGV = map glob, @ARGV} s/a/b/g; s/c/d/g; s/e/f/g; " My/Files/Directory/*.txt


更新

除非您进行了一些更改,否则最好将替换命令放在这样的文件中


Update

Unless you have only a few changes to make it is probably best if you put the substitution commands in a file, like this

BEGIN {
    @ARGV = map glob("\"$_\""), @ARGV;
}

s/a/b/g;
s/c/d/g;
s/e/f/g;

然后您可以像这样在命令行上的一组文件上运行它

Then you can run it on a set of files on the command line like this

perl -i.bak -p changes.pl My/Files/Directory/*.txt

这篇关于使用Perl代码对多个.txt文件应用多个查找和替换正则表达式查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆