How to use ripgrep to replace all matches within all files?

4.2k Views Asked by At

I can use the following command to print all changed file and content in the stdout

rg --passthru -F "red" -r "green" -N

Output:

ip.txt
blue test1
green 2
hello blue world

ip2.txt
blue test1
green 2
hello blue world

ip3.txt
green test1
green 2
hello green world

ip4.txt
green test1
green 2
hello green world

how to write these files with changed content to the original file.

1

There are 1 best solutions below

2
BurntSushi5 On

You can't with ripgrep alone. ripgrep doesn't support it by design. It never writes to files. It only reads them.