Page 1 of 1
Change string in muliple files
Posted: Mon Aug 02, 2004 1:39 pm
by Brujah
Hy fellow programmers,
I started my game with german as the language.
But now I want to change everthing to english to be more international.
So I need to change all the variables in all my files.
Does anybody know a method to acomplish this without having to edit all files per hand?
Posted: Mon Aug 02, 2004 7:35 pm
by Beach
You could use a "sed" command to accomplish this:
Code: Select all
sed "s/GermanVar/EnglishVar/g" filename.pb > filename.eng.pb
This would replace all "GermanVar" with "EnglishVar" in filename.pb and then save as "filename.eng.pb"
Posted: Tue Aug 03, 2004 7:16 pm
by Brujah
Thanks a lot for the hint. That helped a lot already.
But now I got the problem that he does not want to change some special characters.
The documentation to sed is quite huge. I can't figure it out how it works to change this string:
skills(2,
Into this string:
skills(#COMBAT_TRAINING,
I get something like:
bash: syntax error near unexpected token `('
Can somebody here can give me a quick hint for that ?
Posted: Tue Aug 03, 2004 8:59 pm
by Beach
Try escaping the "(" like so:
Code: Select all
sed "s/skills[\(]2/skills(#COMBAT_TRAINING/g" file.txt >newfile.txt
Posted: Wed Aug 04, 2004 3:40 pm
by Brujah
Okay, I wrote a long scripts which contains all the filenames I want to change.
Now I got one more problem

I can't change one file to its own name, then the target file is empty. So I copy all of them to new filenames. Means laby.pb to laby.pb2.
Now I want to change all files ending in .pb2 back to .pb.
Is there another nice command that I do not know which can handle that ?

Posted: Wed Aug 04, 2004 6:29 pm
by Beach
Yes there is, however if it is used incorrectly, it is far from nice!
Just be sure you have a backup first.
Posted: Wed Aug 04, 2004 7:56 pm
by Brujah
Yes, I knew that one.
But its not possible to do a
mv *.pb2 *.pb
Okay, I can create the command in my script to do it.
Means create one move command for each file.
I just thought maybe there is an easier way...
Posted: Wed Aug 04, 2004 8:20 pm
by Brujah
I found a solution

massrename is a perl script I found on sourceforge.
That can rename everything to everything.