ppre user guide

The basics of ppre, a regular-expression tool that finds files, searches text, renames files and edits text with one grammar, in place of find, grep, perl rename and sed.

What is ppre

ppre (Powerful Pattern Replacement Engine) is a command-line tool written in Rust by PPOPPO Corp. Finding files, searching text, renaming files and editing text usually take four tools with four different grammars. ppre does all four with one.

Instead ofUseTo
findppre findFind files by name
grepppre grepSearch file contents
rename (perl)ppre renameRename files
sedppre editEdit file contents
  • One grammar — the four commands share the same word order, the same options and the same pattern language. What you learn for one carries over to the other three.
  • Regular expressions only — files are selected by regular expression too: '\.rs$', not *.rs. There is no second pattern language to switch to.
  • One regex dialect — every command reads a pattern the same way, including lookaround, backreferences and named groups.
  • Nothing is guessed — a spelling ppre does not accept is refused by name. Where a rewrite exists, the error gives it.

Supported platforms are Linux and macOS.

One grammar, four commands

Every command line has the same shape.

ppre <command> [options] <pattern> [path...]

The four commands are the four combinations of two questions: do you mean file names or file contents, and do you want to read or to change?

ReadChange
File namesppre findppre rename
File contentsppre grepppre edit

Only the command word changes. The options, the regular expression and the paths stay where they are.

ppre find -r 'draft'              notes   # list the names that match
ppre grep -r 'draft'              notes   # print the lines that match
ppre rename -r 's/draft/review/'  notes   # rewrite the matching part of each name
ppre edit -r 's/draft/review/g'   notes   # rewrite the matching text in each file
PartRule
<command>find, grep, rename or edit.
[options]One spelling has one meaning on every command. Every command accepts every option. A command that cannot act on an option ignores it, and ppre help <command> lists those options with the reason.
<pattern>A regular expression. The commands that read (find, grep) take it bare. The commands that change (rename, edit) take the same regular expression inside a substitution, s/regex/replacement/, because a change also needs a replacement.
[path...]Files or directories. A file you name is always read. A directory is walked, and -r is what descends into its subdirectories.

These options are honoured by all four commands, with the same meaning.

OptionMeaning
-r, --recursiveDescend into subdirectories. Without it, only the top level of a directory is read.
--max-depth <N>Descend at most N levels (1 = direct children). Implies -r.
-m, --filter <REGEX>Work only on paths that match the regular expression. Repeatable.
--exclude <REGEX>Leave out paths that match the regular expression. Repeatable.
--include-ignoredAlso walk what .gitignore excludes.
--exclude-hiddenSkip hidden entries (names that start with .).
--follow-symlinksFollow symbolic links while walking.
-i, --ignore-caseMatch without regard to case.
--normalizeMatch every Unicode spelling (NFC/NFD) of the text.

The options that differ follow from the job, not from the tool. -n (--dry-run) previews a change, so it belongs to rename and edit. Options that shape a listing, such as -l, -c and -o, belong to grep. The grammar around them does not change.

Installation

ppre is currently built and installed from source. You need a Rust toolchain and just.

just install

This builds a release binary and installs it to ~/.local/bin/ppre, with its manual page (man ppre). Installation stops if another ppre comes first on your PATH, so make sure ~/.local/bin is near the front of PATH.

If you use ppre every day, you can add short aliases to your shell startup file (~/.zshrc or ~/.bashrc).

# ppre shortcuts
alias ppf='ppre find'
alias ppg='ppre grep'
alias ppr='ppre rename'
alias ppe='ppre edit'

After that, ppg -r 'draft' . means ppre grep -r 'draft' ..

First steps

The blocks below show standard output. rename and edit also print a short summary of the run on standard error.

  1. Make three small files to practise on.

    mkdir -p demo/notes && cd demo
    printf 'status: draft\n' > notes/draft-01.md
    printf 'status: draft\n' > notes/draft-02.md
    printf 'status: final\n' > notes/final-03.md
    
  2. Find the files whose name matches draft.

    $ ppre find -r 'draft' .
    ./notes/draft-01.md
    ./notes/draft-02.md
    
  3. Search for the lines that match the same pattern. Only the command word changed.

    $ ppre grep -r 'draft' .
    ./notes/draft-01.md:1:status: draft
    ./notes/draft-02.md:1:status: draft
    
  4. Preview an edit. -n changes nothing, and --diff prints the change as a unified diff.

    $ ppre edit -r -n --diff 's/draft/review/g' .
    --- a/notes/draft-01.md
    +++ b/notes/draft-01.md
    @@ -1,1 +1,1 @@
    -status: draft
    +status: review
    --- a/notes/draft-02.md
    +++ b/notes/draft-02.md
    @@ -1,1 +1,1 @@
    -status: draft
    +status: review
    
  5. Run the same line without -n and --diff to apply it.

    ppre edit -r 's/draft/review/g' .
    
  6. Preview a rename, then apply it. The output is the plan: the old name, a tab, the new name.

    $ ppre rename -r -n 's/draft-(\d+)/review-$1/' .
    ./notes/draft-01.md	./notes/review-01.md
    ./notes/draft-02.md	./notes/review-02.md
    $ ppre rename -r 's/draft-(\d+)/review-$1/' .
    ./notes/draft-01.md	./notes/review-01.md
    ./notes/draft-02.md	./notes/review-02.md
    
  7. Check the result.

    $ ppre find -r '\.md$' .
    ./notes/final-03.md
    ./notes/review-01.md
    ./notes/review-02.md
    

Regular expressions

One dialect serves every place a pattern goes: the pattern of find and grep, the pattern half of a substitution in rename and edit, and the value of --filter and --exclude.

SyntaxMeaning
\d \w \s .A digit, a word character, white space, any character
^ $ \bStart and end of a line (of the name, for find and rename), word boundary
* + ? {2,4}Repetition. Add ? for the shortest match: .*?
(…) (?<name>…)A group, a named group. Groups need no backslash
(?=…) (?!…)Lookahead, negative lookahead
(?<=…) (?<!…)Lookbehind, negative lookbehind (fixed width)
\1 \k<name>Backreference to a group
(?>…)Atomic group

A glob is not a pattern. ppre find -r '*.md' . is refused, and the error gives the regular expression to use. The same holds for -g, which points at --filter.

GlobRegular expression
*.txt\.txt$
test_*^test_
*config*config

Spellings whose meaning differs between regex engines are refused by name too: possessive quantifiers (a++), recursion ((?R)), \K and variable-width lookbehind. Where a rewrite exists, the error gives it.

For find and grep, -F takes the pattern as literal text and -e adds another pattern (either may match).

Substitutions

rename and edit take the expression that sed and perl rename take.

s/regex/replacement/flags
  • Delimiter — another punctuation character such as # or | can replace /, which helps when the text holds slashes: s#/usr/local#/opt#.
  • Flags — g replaces every match. Without it, only the first match in each file (or name) is replaced. i ignores case, s lets . match a line break, U makes repetition match the shortest text.
  • Transliteration — y/a-z/A-Z/ maps characters one for one. Both sets must have the same length.

The replacement is a superset of sed's. Every sed spelling works, and the $ forms work beside it.

In the replacementMeaning
\1 … \9, $1, ${1}A numbered group
${name}A named group
&The whole match
\U \L … \EUpper case or lower case up to \E
\u \lUpper case or lower case for the next character
\n \tA line break, a tab
$$A literal $
ppre edit 's/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/${d}.${m}.${y}/g' dates.txt   # 2026-11-24 → 24.11.2026
ppre edit 's/_(\w)/\u$1/g' names.txt                                           # hello_world → helloWorld
ppre rename 's/\.(\w+)$/.\L$1\E/' *.TXT                                        # readme.TXT → readme.txt

Coming from find, grep, rename and sed

Habitppre
find . -name '*.rs'ppre find -r '\.rs$' .
find . -type d -name 'src'ppre find -r -t d '^src$' .
find . -maxdepth 1 -name '*.md'ppre find --max-depth 1 '\.md$' .
grep -rn 'TODO' srcppre grep -r 'TODO' src
grep -r --include='*.rs' 'TODO' .ppre grep -r -m '\.rs$' 'TODO' .
grep -rl 'TODO' .ppre grep -rl 'TODO' .
rename 's/\.txt$/.md/' *.txtppre rename 's/\.txt$/.md/' *.txt
rename -n 's/old/new/' *.txtppre rename -n 's/old/new/' *.txt
sed -i 's/old/new/g' file.txtppre edit 's/old/new/g' file.txt
sed -i -E 's/(a)(b)/\2\1/g' file.txtppre edit 's/(a)(b)/\2\1/g' file.txt
find + xargs sed -i over a treeppre edit -r -m '\.rs$' 's/old/new/g' .

Four things differ from the habit.

  • -r descends. find walks the whole tree by default. ppre reads the top level until -r or --max-depth says otherwise, and a run that stayed at the top level says so.
  • Regular expressions, not globs. '\.rs$' where find -name and grep --include take '*.rs'.
  • Groups without backslashes. (…) groups and \d is a digit, with no -E to remember.
  • g covers the file. sed without g replaces the first match on every line. ppre edit without g replaces the first match in the file. Write g to replace every match.

A pipe with no path is the input for grep and edit, as it is for grep and sed.

git log --oneline | ppre grep -i 'fix'
git log --oneline | ppre edit 's/^(\w+) /[$1] /g'

Good to know

  • What a walk reads — inside a git repository a walk skips what .gitignore excludes. It reads hidden files and never enters .git/. A path you name on the command line is always read, whatever the filters say.
  • Edits are backed up — edit saves the original under .ppre_backups/ before it writes. ppre restore --list shows the backups, and ppre restore --checkpoint <ID> puts a whole run back. Set PPRE_BACKUP=none to keep no backups.
  • Renames are planned — rename changes only a file's own name, never its directory. Every rename is planned before the first one runs, so two files that would land on one name are refused before anything moves. A rename takes no backup. Its output is the record, and the inverse expression undoes it.
  • Output pipes cleanly — standard output holds the result and nothing else. Summaries and notes go to standard error.
  • Exit codes — 0 success, 1 nothing matched (find, grep), 2 partly done, for example when a file could not be read. An error such as an invalid pattern or a missing path exits with 10 or above.
  • Korean names on macOS — a name stored decomposed (NFD) does not match text typed composed (NFC). ppre says so when it happens, and --normalize matches both.
  • More help — ppre help <command> and man ppre hold the full reference. ppre learn basics is a regular-expression tutorial.