Search & Replace using rpl

rpl is a very useful command used for bulk string replacement in files. Basic usage is to specify two strings and one or more filenames or directories on the command line. The first string is the string to replace, and the second string is the replacement string. Another Linux command used to replace string is sed.

To instal rpl on Ubuntu or Debian, use

To install from source

Here are some of the command-line options for rpl command.

Examples

Replace string in one file.

Replace in multiple files

To replace all occurrences of CAT with RAT run the following command, it will go through all files and do the replacement.

-x specify file extensions you need to replace. In above case, it only replace in files with .php, .html and .htm file extensions.
-R option is used to change recursively.

Replace all occurences of ”F” (on word boundaries) with ”A” in all text files under the grades/ directory:

See sed.

Leave a Reply

Your email address will not be published. Required fields are marked *