How to change same value in multiple files (Windows)

johann@nenni.net
johann@nenni.net's picture

Joined: 2003-09-01
Posts: 43
Posted: Mon, 2005-04-11 12:07

Little trick for people who do not know how...

To change same text in many files there are many methods, some easy other not so...

For ex. to change "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" to :"Plural-Forms: nplurals=2; plural=n != 1;\n"

In this example I only needed to change the "INTEGER" and "EXPRESSION" to correct values this can be done like this:
sed -s "s/INTEGER/2/" -e "s/EXPRESSION/n != 1/" filename.po >filename.po.new

To do this on many files I use this command "for /f %i in ('dir /b /s *.po') do sed -e "s/INTEGER/2/" -e "s/EXPRESSION/n != 1/" %i > %i.new"

Then i double-check my new file and if correct i do "move" "for /f %i in ('dir /b /s *.po') do move /Y %i.new %i

I use sed.exe from unxutils http://unxutils.sourceforge.net, who also have many other useful text utils for windows users. Like those we know from Linux...

(You can also change the file "inplace" by adding the -i parameter, but I don't like that...)