beyondgrep / ack3

ack is a grep-like search tool optimized for source code.
https://beyondgrep.com/
Other
711 stars 66 forks source link

Request: --no-group-separator option #363

Open hftf opened 2 years ago

hftf commented 2 years ago

Ack, grep, and other programs sensibly print -- between groups of context (-A/-B/-C). However, it would be nice to disable the -- with an option especially when the output will be further processed. GNU grep has a --no-group-separator option for this.

See also https://stackoverflow.com/questions/2168065/how-do-i-get-rid-of-line-separator-when-using-grep-with-context-lines.

petdance commented 2 years ago

Seems useful. First thing that comes to mind is that we may have confusing with --group/--nogroup. I'm not saying that's a show-stopper.

Please tell me about how you would use this.

hftf commented 2 years ago

For an example, I have a log of stenography keystrokes pressed (one stroke per line) and use the -A/-B/-C context feature to get all strokes before or after an undo stroke, so I can see which words I commonly mistype and what are the misstrokes I write instead. Further processing of the output is done to extract the words from within the log's line format, sort, tally, etc. I don't need the group separators during further processing, although it doesn't get in the way too badly.

glanois commented 11 months ago

@petdance says

Please tell me about how you would use this.

space-track.org publishes satellite orbital elements (3 lines per satellite - first line is the name, and the 2nd and 3rd lines are the data). I use ack with -A 2 as a filter to select satellites by name.

I really don't want the -- in the output - it breaks my downstream applications.

Here is the documentation of the format: https://www.space-track.org/documentation#tle-basic

Would appreciate it if you were to add this --no-group-separator option.

As a workaround I'm just using Gnu grep for this step.

petdance commented 11 months ago

As a workaround I'm just using Gnu grep for this step.

That doesn't sound like a workaround. It sounds like using the right tool for the job.

If the use case is a pipeline, and grep works, I'd suggest using grep. ack is geared towards being read by humans on a screen.