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 --no-column flag to override --column (and --vimgrep) #880

Closed
kenorb opened this issue Apr 11, 2018 · 18 comments
Closed

add --no-column flag to override --column (and --vimgrep) #880

kenorb opened this issue Apr 11, 2018 · 18 comments
Labels
enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue.

Comments

@kenorb
Copy link

kenorb commented Apr 11, 2018

ripgrep should have a --no-column flag as a way to toggle the --column flag. Like --no-line-number, this should also override --vimgrep.

@BurntSushi
Copy link
Owner

Your output shows column numbers, not line numbers.

Could you please explain what problem you're trying to solve? --vimgrep is meant specifically for parsing by external programs, particularly vim. Using it in conjunction with --no-filename --no-line-number seems strange to me.

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Apr 11, 2018
@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

I just need the plain output without any extras. Basically what it reads "a line with more than one match will be printed more than once", so I can count the duplicates.

@BurntSushi
Copy link
Owner

BurntSushi commented Apr 11, 2018

Your sentences seem to be in conflict with each other. "Plain output" to me is "print every line that matches." rg pattern file -N will do that when at a tty.

If you want each match to be on its own line, then rg pattern file -N -o will do that. The -o/--only-matching flag is the same one found in GNU grep.

@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

It's basically for the workaround to do AND grepping which I haven't found, so:

rg --vimgrep --no-filename --no-line-number "foo|bar|buzz" file.txt | sort | uniq -c | sort -nr | grep -w 3

should show me only the lines with all 3 patterns present, but because of extra column numbers, it doesn't work. So for further workaround, I'll have to filter out the output using awk and/or cut by removing these column numbers.

@BurntSushi
Copy link
Owner

@kenorb You're overthinking it. Look at the output of rg 'foo|bar|buzz' file.txt | cat. ripgrep toggles slightly different options depending on whether you're piping or printing to a tty.

@BurntSushi
Copy link
Owner

See also: rg 'foo|bar|buzz' file.txt -o | cat.

@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

I need basically foo&bar&buzz-like pattern, so I need line with all patterns present at the same time, which would be foo bar buzz in this case. So having 3 the same lines and counting the duplicates could help me to find those lines.

@BurntSushi
Copy link
Owner

BurntSushi commented Apr 11, 2018

@kenorb Then I have no idea what you're doing. rg foo | rg bar | rg buzz prints only the lines that contain foo, bar and buzz. You should be solving this problem the same way you'd solve it with grep.

@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

I know, but I was looking for some method to run rg only once for simplicity, but it didn't end well.

@BurntSushi
Copy link
Owner

Then why in the world did you file a bug report about --vimgrep? I am very confused.

@BurntSushi
Copy link
Owner

If that's what your after, then I guess you probably want #875. (It's not clear whether it will ever happen.)

@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

I would expect that --no-line-number would suppress column numbers as well. Otherwise, I'd expect another param like --no-column-number which is not there.

@BurntSushi
Copy link
Owner

BurntSushi commented Apr 11, 2018

--no-line-number does suppress line numbers, even when paired with --vimgrep. So your expectation is satisfied already.

A request for a --no-column flag (to match the existing --column flag) is reasonable, but merely for consistency sake.

As far as I can tell, your use of --vimgrep here makes no sense at all. So if you don't want column numbers, then don't use it.

@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. help wanted Others are encouraged to work on this issue. and removed question An issue that is lacking clarity on one or more points. labels Apr 11, 2018
@BurntSushi BurntSushi changed the title -N doesn't suppress line numbers completely when used with --vimgrep add --no-column flag to override --column (and --vimgrep) Apr 11, 2018
@kenorb
Copy link
Author

kenorb commented Apr 11, 2018

So I would expect this output:

$ rg --vimgrep --no-filename --no-line-number "foo|bar|buzz" file.txt  | cut -d: -f2-
foo
foo bar
foo bar
foo bar buzz
foo bar buzz
foo bar buzz

but without cut which won't work anyway when there are multiple-digits. So if --no-line-number can't support suppressing column numbers, then I'd expect --no-column-number.

@BurntSushi
Copy link
Owner

I've updated this issue to reflect the actual request.

@BurntSushi
Copy link
Owner

@kenorb OK, I'm finding this conversation to be frustrating. It's going in circles. I don't know where, how or why you're confused. If this is just a request for something as simple as --no-column, then fine. Let's leave it at that. But your examples with --vimgrep and your questions about "and" grepping combined with all this talk about cut, awk and showing patterns that actually do "or" grepping has made this issue way harder to understand than it needs to be.

@okdana
Copy link
Contributor

okdana commented Apr 11, 2018

Seems like the reason @kenorb is interested in --vimgrep is just that it causes rg to print one copy of a line for each time it matches the pattern. I don't think (?) that functionality is exposed through any other option. So his request could be fulfilled either by adding an option to disable column numbers, which could be combined with --vimgrep, or by adding a new option that just enables that duplicate-printing behaviour. I think that's it, anyway?

@BurntSushi
Copy link
Owner

@okdana Thanks for lending some clarity to this issue! I forgot that --vimgrep emitted the entire line, which is of course different than what -o does.

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. help wanted Others are encouraged to work on this issue.
Projects
None yet
Development

No branches or pull requests

3 participants