Price: $0 (Copyrighted FreeWare)
Current Version: 1.4.1
Date Modified: April 24, 2008
Featured as Tool of the Month on UnixReview!
Overview
Detailsrpl is a UN*X text replacement utility. It will replace strings with new strings in multiple text files. It can work recursively over directories and supports limiting the search to specific file suffixes.
rpl [-iwRspfdtx [-q|-v]] <old_str> <new_str> <target_file(s)>
rpl replaces old_str with new_str in all target files. It returns the number of strings replaced or a system error code (non-zero) if there is an error.Note that you should put strings in single quotes if they contain spaces. You must also escape all shell meta-characters. It's a good idea to put ALL strings in single quotes.
If one of the strings starts with a "-" you need put "--" as the last argument BEFORE the string. This will prevent the options parser from treating the string as a command- line option.
For Example:
rpl -i -- '-8x' '+8x' myfile
which would replace occurences of "-8x" with "+8x" in the file myfile (ignoring case).
A period will be printed to stderr as each target file is processed to give you feedback on the replacement progress.
You may use the quiet (-q) option to suppress all output but major error reporting.
rpl will attempt to maintain the owner, group and permissions of your original files. For safety, rpl creates a temporary file and makes changes to that file. It then moves the temporary file over the original file. rpl sets the owner, group, and permissions of the new file to match those of the original file. In some circumstances rpl will not be able to do this (such as when a file is owned by the superuser but you have group write permission). In these cases rpl will warn you that the owner/group or permissions cannot be set and that file will be skipped, unless you use the force (-f) option. Note that the use of temp files in predictable, world-writeable locations could lead to symlink attacks. Ideally you should set the $TMPDIR environment variable to a private directory readable and writeable only by you. This is especially important if running rpl as root. You have been warned!
rpl can be placed in silumation mode (-s), in which rpl will print a list of files that would be modified if an actual replace operation were executed. This is useful when you are about to make changes to a larger group of files, possibly in many directories.
rpl can be placed into prompt mode (-p). In this mode rpl will examine each file, printing a period as each file is scanned. If a match is found rpl will prompt you to save the replacements made to that file. Answering "y", or pressing Return will save the changes. Answering "n" will leave that file untouched. rpl will then move on to the remaining target files. Note that you will only be prompted for files which had a match. If no match is found a period is printed to give you an indication that rpl is working. (This is useful when, for instance, you are performing a large recursive batch replacement on a collection of files.)
Normally, rpl will change the modification time of all files it processes like any other program. However, you may instruct rpl to keep the original modification times using the -d (Don't alter mod-times) option.
You can specify file suffixes to be searched using the -x option. Any files that do not match the specified suffixes will not be searched or modified. The -x option may be used more than once to tell rpl to search files with varying suffixes. For instance, say you wanted to search all of your ".html", ".htm", and ".php" files you would add " -x'.html' -x'.htm' -x'.php' " to your command line. rpl would then skip any files that did not end with these suffixes. This is mainly useful when doing recursive searching (-R option).
OPTIONS
-i Ignore case of old_str rpl will match the old_str in the searched file regardless of the case. The case of new_str will not be altered. -w Whole words (old_str bounded by white space in file) rpl will only match old_str if it is bounded by the start of a line, a space, a tab, or the end of a line. -q Quiet mode (no output at all) Good for shell scripts, etc. -v Verbose mode (lots of output) rpl will list the name of each file and directory, and the line numbers that contain matches. -R Search directories recursively rpl will scan every file and every directory recur- sively. Without this option directories will be skipped. -x Specify file suffixes to search. (e.g. ".html", ".c", etc.) May be used multiple times. See above for details. -p Prompt for each file rpl will prompt you before scanning each file. If you respond 'N' or 'n' rpl will skip that file and move on to the next file. The default action if you press enter is to process the file. -s Simulation mode rpl will scan all of the files and list the names of files that it would modify if a replace opera- tion was executed. If you turn on the verbose (-v) option as well rpl will list the line numbers where the string was matched. -e Honor Escapes rpl will honor escape sequences in old_string and new_string. Standard escapes such as "\t" (tab), "\n" (newline), "\r" (carriage return) are processed, as well as any octal or hexidecimal ASCII codes. Octal ASCII codes start with a '\' and are comprised of three digits [0-7] (e.g. '\015'). Hexidecimal ASCII codes start with '\0x' followed by two characters [0-f] (e.g. '\0x0d'). The 'x' and the [a-f] may be upper or lowercase. When you use this switch you must escape all backslash ('\') characters with another backslash (e.g. '\\'). -f Force mode rpl will overwrite files even if the owner, group, or permissions of the new file will not match the original. Obviously, rpl cannot overwrite files if the user does not have write permission. -d Don't change modification times rpl will process files, but keep their original modification times. -t Use $TMPDIR for temporary files Causes rpl to write temporary files to the direc- tory specified by the environment variable $TMPDIR instead of writing the temp files to the original file dir. -L Display the software license This displays the software license that you agree to by using rpl. -h Display a brief summary of options
Support Forum
Please join us at SourceOpen.com, and don't be afraid to be one of the first people to post a comment, question, etc. !
Download
Digital Signature
As of 1.3.0b3 we have begun signing our software with GPG. Our GPG public key can be found here.
Version 1.4.1 (changes to ease compiling changes only--otherwise the same as 1.4.0)
(60K) - GZIPed TAR file (source code, Install directions, & man page)
(60K) - GZIPed TAR file (source code, Install directions, & man page)
(60K) - GZIPed TAR file (source code, Install directions, & man page)
(60K) - GZIPed TAR file (source code, Install directions, & man page)
(12K) - GZIPed TAR file (source code, Install directions, & man page)
(19K) - SRPM file (source code, & man page)
Note: Non-rpm Binaries are static-linked (except OS X), making the executable more compatible, but larger. You may wish to download the source instead. It is very easy to compile. RPMs are not static-linked
Version 1.4.0
(Some are not ready yet! Use the source, Luke!)
Note: Due to the bugfix in 1.4.0 you should really use that version.
(31K) - RPM file (precompiled binary RPM, man page)
(31K) - RPM file (precompiled binary RPM, man page)
Version 1.3.0b3
(13K) - RPM file (precompiled binary RPM, man page)
(13K) - RPM file (precompiled binary RPM, man page)
(19K) - GZIPed tar file (precompiled binary, man page, install script, source)
Browse the server for other versions: HTTP FTP