ack3
ack3 copied to clipboard
Supress printing of line numbers
ack v3.4.0 always prints line numbers:
123: Hello, World!
Is there an option to not print line numbers, eg.
Hello, World!
Curiously, the help and man pages say nothing of this fundamental functionality.
#142 might relate to this, but nothing happening there for a couple of years.
Does this mean we are stuck with line numbers?
Can you give a specific command line that you're having problems with?
Does the -h not do what you want?
-h surpresses both filenames and line numbers (though the latter is not mentioned in the man pages). I want to keep filenames, but surpress line numbers.
-h, --no-filename
Suppress the prefixing of filenames on output when multiple files
are searched.
If I'm understanding, instead of
t/text/amontillado.txt
61:"And yet some fools will have it that his taste is a match for your
98:the foot of the descent, and stood together on the damp ground of
156:"A huge human foot d'or, in a field azure; the foot crushes a serpent
t/text/raven.txt
93:Swung by seraphim whose foot-falls tinkled on the tufted floor.
you want:
t/text/amontillado.txt
"And yet some fools will have it that his taste is a match for your
the foot of the descent, and stood together on the damp ground of
"A huge human foot d'or, in a field azure; the foot crushes a serpent
t/text/raven.txt
Swung by seraphim whose foot-falls tinkled on the tufted floor.
Why is that? What's the use case? Not arguing, just trying to understand.
Exactly. I think it was where the length of the line number string varied from 1 to 4 characters, thereby skewing the text content on lines accordingly, making it difficult to relate them to each other. Suppressing line numbers would seem like a one-liner, though I fully support developer inertia to prevent feature bloat. An alternative would be to right-align the line numbers, eg. printf("%'*d"), though I think suppressing line numbers seems like the proper fix with many potential benefits.
Knowing how many digits to allow %*d either requires scanning the whole file before output or a heuristic for the largest sensible filesize in lines when the inode only saves filesize in bytes (not even in characters, but bytes).
Not an impossible heuristic: log10($filelength_bytes) is a firm, generous, but not crisp upper bound on number of digits in a linenumber
(assuming we don't count VT as some multiple of CRLFs !!).
(A crisp heuristic that is never wrong will be hard.)
it may be all the way back in ack1.$large that I last spoke in favor of --[no-]line-number for full control of output, since i don't see my handle on comments on the referenced Ack3.0 ticket nor it's Ack2 precursor.
I support full control of line numbering separable from filenames
since there are times that I do want filenames but not line numbers,
and having filenames once as headers rather than inline as : delimited fields is often preferable (but of course not always)
so the obvious piping to cut -d: -f won't do what i want either.
I will note a weird workaround that does work - putting the cut into the ack pager option avoids interlining the filename:
ack get_file_id --pager='cut -d: -f2|less -iR'
Not intuitive but it works!
(This workaround could be included pro tempore in Cookbook https://github.com/beyondgrep/website/issues/103 )
Sometimes I find line numbers to be distracting, especially when reading the search result with context option (e.g -C 4). Not having line numbers (along with ":" & "-" prefixes to lines) would help much.