On Sat, Jan 09, 2010, Rudi Ahlers wrote:
I am used to using the replace command to quickly replace strings in file, but it's not available on some of my fresh CentOS 5.4 servers.
"yum info replace", "yum whatprovides replace", and "yum search replace" doesn't show me which package(s) to install to get it. So, does anyone know which package to install to get the "replace" command?
Google doesn't help either since the work "replace" is too common
The original replace command that I used for years was from the Kernighan and Pike ``Unix Programming Environment'', and is a simple shcll script that uses their ``overwrite'' command to safely edit a file in place. The command syntax is:
replace old new file [file ...]
MySQL created their own replace command that has different arguments and calling sequence (not having read K&P obviously which is one of the must-have *nix books :-). I still use the original K&P version, renamed ``csreplace'' to avoid conflicts with the mysql version. I've attached the csreplace and overwrite scripts which can be put someplace in PATH.
A *MUCH* more flexible tool that can be used for editing in place is Ralf Engelschall's shtool script available here:
ftp://ftp.gnu.org/gnu/shtool/
GNU shtool is a compilation of small but very stable and portable shell scripts into a single shell tool. All ingredients were in successful use over many years in various free software projects. The compiled shtool script is intended to be used inside the source tree of those free software packages. There it can take over various (usually non-portable) tasks related to the building and installation of such packages.
The only problem I've found with shtool's subst option is that giving it a bad ``sed'' command results in zero length file(s) so it's a good idea to test complex substitutions.
Bill