alex
alex

Reputation: 95

replace words to all files in the same directory?

is there a way with perl to change al the instances of the tags

<english> into <voice required="name = VW Julie">

<español> into <voice required="name = IVONA 2 Penélope">

for all the documents in the same directory.

this is for textaloud, so the computer changes to other voice when the language changes

i can do it with grep, but it is boring always setting up. would be better if i only double click on the script. but i don't know how to do it, any help is good. thanks

Upvotes: 0

Views: 92

Answers (3)

mpapec
mpapec

Reputation: 50637

This should work on windows,

script.pl

use utf8;
BEGIN { @ARGV = glob("@ARGV\\*"); }
s/<english>/<voice required="name = VW Julie">/g;
s/<español>/<voice required="name = IVONA 2 Penélope">/g;

perl -i~ -p script.pl C:\Path\to\files

Upvotes: 1

Barmar
Barmar

Reputation: 780994

Ths following Unix shell command should do it:

perl -Mutf8 -pie 's/\<english\>/<voice required="name = VW Julie">/g; s/\<español\>/<voice required="name = IVONA 2 Penélope">/g' DIRECTORY/*

The -e option tells perl to run the commands in the next argument. -p tells it to run the commands in a loop for each input line, printing $_ after the command. And the -i option tells it to replace the input files with the output.

I assume this will also work from the Windows command prompt, but I've never used Perl on Windows.

Upvotes: 0

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185116

You could do :

$ cd /PATH/TO/DIRECTORY
$ perl -i -pe -Mutf8 's/<english>/<voice required="name = VW Julie">/g' *
$ perl -i -pe -Mutf8 's/<español>/<voice required="name = IVONA 2 Penélope">/g' *

Upvotes: 0

Related Questions