Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

windows - Apply multiple find and replace regex queries on multiple .txt files using a Perl code

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

changes.pl

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...