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

Add an option similar to -o, --only-matching #34

Closed
dzamlo opened this issue Sep 23, 2016 · 9 comments
Closed

Add an option similar to -o, --only-matching #34

dzamlo opened this issue Sep 23, 2016 · 9 comments
Labels
enhancement An enhancement to the functionality of the software. libripgrep An issue related to modularizing ripgrep into libraries.
Milestone

Comments

@dzamlo
Copy link

dzamlo commented Sep 23, 2016

With grep you can print only the matched parts of the files. The option is described like this in the grep manpage:

-o, --only-matching
       Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

A more powerful option, would something similar to --replace, but that doesn't print the non matched part of the text.

@cwillu
Copy link

cwillu commented Sep 24, 2016

Note that surrounding the search regex with .( ). and then using --replace $1 will do this; pretty verbose though, especially when using it in a pipeline.

@BurntSushi
Copy link
Owner

--replace already exists (and I agree it's kind of verbose for this case).

-o/--only-matching is an option on grep, so I'm OK adding this.

@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label Sep 24, 2016
utkarshkukreti added a commit to utkarshkukreti/ripgrep that referenced this issue Sep 28, 2016
@sergeevabc
Copy link

sergeevabc commented Dec 15, 2016

Input

host -t A wikipedia.org | openssl dgst -sha256 | rg --no-line-number [A-Fa-f0-9]{64}

Output

(stdin)= 0d00409623da8ae039de83200af7f6fa9211bb13e1b3e10ea45142cd08b3e50b

Hash is coloured red, but I need hash (that red part) only.
Would the considered option --only-matching be of help?

@BurntSushi
Copy link
Owner

@sergeevabc Yes, it would solve your problem. But there is a work-around for now:

$ host -t A wikipedia.org | openssl dgst -sha256 | rg -N '^.*([A-Fa-f0-9]{64}).*$' --replace '$1'

@sergeevabc
Copy link

sergeevabc commented Dec 15, 2016

@BurntSushi, thanks, but when --only-matching will be implemented?

@BurntSushi
Copy link
Owner

@sergeevabc I don't know. It happens when it happens. I do this in my free time and I don't typically schedule my free time in advance. Sorry.

@gavinfoley
Copy link

To counterbalance the above comment, I wanted to say that I use and enjoy this excellent tool you've created every day, and I appreciate whatever improvements are made whenever they are made. Thanks for using some of your limited free time to make my life and others' easier.

@BurntSushi
Copy link
Owner

@sergeevabc This issue tracker isn't place to give me advice on how to schedule my free time or to shame anyone into doing work on their free time. Future comments in that vain won't be tolerated.

@BurntSushi BurntSushi modified the milestone: libripgrep Jan 10, 2017
@BurntSushi BurntSushi added the libripgrep An issue related to modularizing ripgrep into libraries. label Jan 11, 2017
kpp added a commit to kpp/ripgrep that referenced this issue Apr 2, 2017
@22a
Copy link

22a commented Apr 9, 2017

Wonderful, thank you for the great work @kpp + @BurntSushi 🎉

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

No branches or pull requests

6 participants