News for hackers. Stuff that matters.
Re:Introducing rep and ren: A New Approach to CLI Find and R... by zaidhaan on Saturday December 30, 2023 @11:48AM (#38816612)
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/

Re:Introducing rep and ren: A New Approach to CLI Find and R... by rgun on Saturday December 30, 2023 @10:15PM (#38821419)
> Not that I'd encourage anyone to do this at all

Why so?

Re:Introducing rep and ren: A New Approach to CLI Find and R... by zaidhaan on Sunday December 31, 2023 @12:19AM (#38822009)
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.