Mihail Radu Solcan

  Change text in a lot of files under GNU/Linux

2007-11-14

I have to make the same change in over one hundred files. Really! I want to change the Romanian quotes from „“ to „”. 

I am going to use a very simple bash script. But one has to be very very cautious with this kind of script. Back-up first the files you are going to change! At least make an archive with the files that you are going to (try to) change. 

In order to make the changes I wrote a bash script which looks like this. The script contains a for-loop in bash; it scans all the tex files (I have to change only the LATEX files). The third line uses sed. The stream editor (sed) actually makes the substitutions. The tempfile must not exist among the files that we change! Use a convenient name. 

Download the script and use it with care. In my case the script works without problems. I checked the changes with

grep -R ” *

It is easy to change the script, but it is also easy to destroy a lot files. Before you use it, test carefully any changes. Look for any side-effect that my ruin a lot o files.