Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: search and replace strings in different files in a directory

by McA (Priest)
on Aug 07, 2014 at 10:23 UTC ( [id://1096587]=note: print w/replies, xml ) Need Help??


in reply to search and replace strings in different files in a directory

Hi,

have a look at perldoc perlrun to see some ways of calling Perl to do some very convenient tasks on the command line.

In your case I'm pretty sure you can do your annoying job with:

perl -pi.bak -e 's{&}{&amp;}g; s{&amp;amp;}{&amp;}g; s{\s>\s}{&gt;}g; +s{\s<\s}{&lt;}g;' *.xml

Regards
McA

Replies are listed 'Best First'.
Re^2: search and replace strings in different files in a directory
by PitifulProgrammer (Acolyte) on Aug 13, 2014 at 10:51 UTC
    Dear McA,

    Thanks a mil for your help with command line editing and sorry for not saying thanks a wee bit earlier.

    The script ran smoothly and did everything as expected. However, I've been running the script via cygwin and was wondering if I could just transform it into a batch file (for all those who do not use cygwin).

    I am a bit concerned if *.xml would be interpreted correctly by a WIN/DOS system.

    Thanks a mil again for the cmd-solution.

    Looking forward to your reply

    Kind regards

    C.
      I am a bit concerned if *.xml would be interpreted correctly by a WIN/DOS system.

      Good point. DOS, Windows and OS/2 leave resolving wildcards to the application, whereas Unix and friends resolve wildcards in the shell. (See also Re^3: Perl Rename.) Luckily, someone has already taken care of this: Win32::Autoglob. Win32::Autoglob also "just works" (by doing nothing) on other platforms than Windows. (Unfortunately, this means Win32::Autoglob does NOT work as expected for DOS and OS/2, but as both platforms went the way of the dodo, this does not harm many people.)

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1096587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-18 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found