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

passthru replace #997

Closed
LippyBoy opened this issue Jul 29, 2018 · 3 comments · Fixed by #1017
Closed

passthru replace #997

LippyBoy opened this issue Jul 29, 2018 · 3 comments · Fixed by #1017
Labels
enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries.
Milestone

Comments

@LippyBoy
Copy link

What version of ripgrep are you using?

0.81

How did you install ripgrep?

releases deb

What operating system are you using ripgrep on?

Ubuntu 16.04

Describe your question, feature request, or bug.

It would be really great if the replace flag worked with the passthru flag - that is, it will replace everything that matches the regex, but will still output non-matching lines.

I know that you can use sed for this, but ripgrep is much more convenient and user friendly, and also highlighting the replacements is great.

Use cases:

  1. Multiple replaces - when you want to replace multiple things, you can't chain ripgreps since strings that aren't matched by the first replace won't be inputted into the second, so it won't replace them
  2. Replacing paths - sometimes I read other people logs, and for the sake of convenience I want to replace their file paths with mine - no problem, just replace the prefix, but of course I can't do it currently in ripgrep since all other logs will be omitted.
  3. This stack overflow question I stumbled upon could have bin solved with this feature: https://stackoverflow.com/questions/51504318/how-to-replace-a-with-o-with-0-in-a-word-list-and-remove-the-unchanged-wor
@BurntSushi
Copy link
Owner

The replace flag should already be working with passthru. If it isn't, that sounds like a bug. Could you please provide a small reproducible example, asking with actual and expected output?

@LippyBoy
Copy link
Author

~/rust> rg --version
ripgrep 0.8.1
-SIMD -AVX
~/rust> 
~/rust> rg --passthru --replace b a
error: The argument '--replace <REPLACEMENT_TEXT>' cannot be used with '--passthru'

USAGE:
    
    rg [OPTIONS] PATTERN [PATH ...]
    rg [OPTIONS] [-e PATTERN ...] [-f FILE ...] [PATH ...]
    rg [OPTIONS] --files [PATH ...]
    rg [OPTIONS] --type-list

For more information try --help
~/rust> 

@BurntSushi
Copy link
Owner

@LippyBoy Hah, nice. I suspect I added that because the implementation simply doesn't support it.

I'll look into adding this as part of libripgrep by not implementing --passthru as a hack.

@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries. labels Jul 29, 2018
@BurntSushi BurntSushi added this to the libripgrep milestone Jul 29, 2018
BurntSushi added a commit that referenced this issue Aug 19, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
BurntSushi added a commit that referenced this issue Aug 20, 2018
This commit updates the CHANGELOG to reflect all the work done to make
libripgrep a reality.

* Closes #162 (libripgrep)
* Closes #176 (multiline search)
* Closes #188 (opt-in PCRE2 support)
* Closes #244 (JSON output)
* Closes #416 (Windows CRLF support)
* Closes #917 (trim prefix whitespace)
* Closes #993 (add --null-data flag)
* Closes #997 (--passthru works with --replace)

* Fixes #2 (memory maps and context handling work)
* Fixes #200 (ripgrep stops when pipe is closed)
* Fixes #389 (more intuitive `-w/--word-regexp`)
* Fixes #643 (detection of stdin on Windows is better)
* Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird)
* Fixes #764 (coalesce color escapes)
* Fixes #922 (memory maps failing is no big deal)
* Fixes #937 (color escapes no longer used for empty matches)
* Fixes #940 (--passthru does not impact exit status)
* Fixes #1013 (show runtime CPU features in --version output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants