Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: add option for "in place" find and replace #2115

Closed
ElectricRCAircraftGuy opened this issue Jan 2, 2022 · 2 comments
Closed
Labels
duplicate An issue that is duplicative of another.

Comments

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Jan 2, 2022

Describe your feature request

Please add a -i / --in-place option (like in sed) to edit files in place. I'd really like to use ripgrep for find and replace across code bases, since it's so fast, but currently it requires some pretty difficult work-arounds to accomplish the desired behavior.

Ex: for a single file I do this to replace all instances of blue with red in file ip.txt:

file_contents_and_stats="$(rg --stats --passthru 'blue' -r 'red' ip.txt)"
NUM_STATS_LINES=9
file_contents="$(head -n -$NUM_STATS_LINES "$file_contents_and_stats")"
stats="$(tail -n $NUM_STATS_LINES "$file_contents_and_stats")"
printf "%s" "$file_contents" > ip.txt
printf "%s" "$stats"

...but when trying to find across many files, this becomes much much harder, and I must first obtain a file list with rg -l then operate on that.

@BurntSushi
Copy link
Owner

Dupe of #74.

@BurntSushi BurntSushi added the duplicate An issue that is duplicative of another. label Jan 2, 2022
@ElectricRCAircraftGuy ElectricRCAircraftGuy changed the title Feature Request: add -i option for "in place" find and replace Feature Request: add option for "in place" find and replace Jan 2, 2022
@ElectricRCAircraftGuy
Copy link
Author

ElectricRCAircraftGuy commented Jan 4, 2022

For anyone looking for this feature, see here; I just wrote a wrapper and added it: #74 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate An issue that is duplicative of another.
Projects
None yet
Development

No branches or pull requests

2 participants