Hacker News new | ask | show | jobs
by zaidhaan 896 days ago
It might be worth noting that while ripgrep doesn't support in-place file editing, it's still possible to replace matches using the `-r` flag, couple that with a tool like `sponge` from moreutils[0] and you can effectively perform search and place like such:

    $ rg --passthru search -r replace file.txt | sponge file.txt
And preview changes like this:

    $ rg --passthru search -r replace file.txt | diff -u file.txt -
Of course, this is only practical when working with a single file. Though I'd imagine if one threw in the `--files-with-matches -0` flags together and piped that into `xargs`, something similar to `rep` could be be achieved. (Not that I'd encourage anyone to do this at all)

[0] https://joeyh.name/code/moreutils/

1 comments

> Not that I'd encourage anyone to do this at all

Why so?

Honestly, upon further thought I think it should be fine as long as the diffs look good.

I just personally would feel more confident with using perl for anything to do with multi-file substitutions. In theory, ripgrep with `--passthru` and `-r` should work.