slightly belated thursday tip day find and replace text in multiple files
Apologies for the delay- it’s been a roller-coaster week at Archaeogeek Towers due to family health issues. Hopefully it’s getting sorted now though.
In the process of preparing Portable GIS, I needed to change a string in multiple files of multiple formats within multiple folders. I looked at various windows- based options, most of which had a charge associated with them, but one of my colleagues suggested a linux approach.
“Sed” is the command that you need, found in most linux systems. In windows you can install it as part of the unxutils toolkit. The following command in linux works recursively through the folders in a root directory changing string1 for string2 (be careful with those single quotes if copy and pasting as wordpress likes to restyle them):
find ./ -type f -exec sed -i ’s/string1/string2/’ {} ;
With a large number of files this might take some time to work (a usb stick took an hour to work through on my ubuntu server vm but maybe that’s not a fair benchmark).