Using the 'replace' utility to change text inside of files on the Unix/Linux OS

Category: Software and Systems Engineering
Author: Sean O'Donnell
Thu, Feb. 20th, 2003 @ 2:20:22 (MST)

If you are running MySQL on Unix or Linux, then I suggest you try using the 'replace' program to easily and quickly replace strings in files on your server.

Replacing a single string, from a single file

The following is an example of the command usage:

/usr/bin/replace -v "test1 test2" -- /home/seanodonnell/private_docs/testing.txt

The example above will easily open the file "/home/seanodonnell/private_docs/testing.txt" and replace the string 'test1' with the new string 'test2'.

Replacing a single string, from a multiple files

Here is another example of how to replace a string from multiple files in a directory:

/usr/bin/replace -v "test1 test2" -- /home/seanodonnell/private_docs/*

The example above will replace the string 'test1' with the new string 'test2' in all files within the '/home/seanodonnell/private_docs/' directory.

Replacing multiple strings, from a single file

The following example will show you how to replace multiple strings from a single text file.

/usr/bin/replace -v "test1 test2 test2 test3" -- /home/seanodonnell/private_docs/testing.txt

The example above should replace the string 'test1' with the new string 'test2', and then the string 'test2' will be replaced by the new string 'test3', in the '/home/seanodonnell/private_docs/testing.txt' file.

Copyleft (<) 1998-2019 www.seanodonnell.com