unix search-and-replace: rpl (and sed)

Evan showed the world his “weak Ruby script” to find-and-replace in multiple files, and was pointed to the amazing rpl utility.

Let’s see what the port maintainer has written about the rpl tool.


$ port info rpl
rpl 1.4.0, textproc/rpl (Variants: universal)
http://www.laffeycomputer.com/rpl.html

rpl is a Unix text replacement utility. It will replace strings with new
strings in multiple text files. It can scan directories recursively and
replace strings in all files found. The search can be limited to files with
certain filename suffixes (e.g. '.html', '.c', etc.).

Platforms: darwin
Maintainers: mich@freebsdcluster.org

Usage context: When you work on auto-setup of new projects (say, making your simplification pipeline even simpler) you can use rpl on configuration files, say, and have non-conflicting markers like MEGASKULLYOUR\_PROJECT_NAMEMEGASKULL which would be replaced by your configuration strings.

Or, when you find a new name for something, and just need to try out this tool

Update: got it to work with sed, which is everywhere. The machine I worked on had FreeBSD, but the port command didn’t answer.


  sed -e 's/max_preview_size = 262144/max_preview_size = 10000000/g' -i boook trac.ini

A breakdown, dear reader:

-e means add a command. s is for substitution of one sequence for another. g is for globally in given files, it could also be a number, say 1, meaning “replace match number 1”.

-i means “irritatingly in-place editing”

-i boook means “…and since it is irritating, add the backup file trac.ini.boook as it were before those edits, to not annoy more than necessary”

[tags]textprocessing,unix[/tags]

Published by olleolleolle

Olle is a programmer, enjoying sunny Malmö in Sweden.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.