Change string in muliple files

Linux specific forum
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Change string in muliple files

Post 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?
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post 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"
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Post 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 ?
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Try escaping the "(" like so:

Code: Select all

sed "s/skills[\(]2/skills(#COMBAT_TRAINING/g" file.txt >newfile.txt
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Post 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 ? :-)
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Yes there is, however if it is used incorrectly, it is far from nice! :)

Code: Select all

mv laby.pb2 laby.pb
Just be sure you have a backup first.

Code: Select all

tar cvf pbfiles.backup.tar *.pb2
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Post 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...
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Post by Brujah »

I found a solution :-)
massrename is a perl script I found on sourceforge.
That can rename everything to everything.
Post Reply