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

Supress printing of line numbers #311

Open
forthrin opened this issue Jul 7, 2020 · 8 comments
Open

Supress printing of line numbers #311

forthrin opened this issue Jul 7, 2020 · 8 comments

Comments

@forthrin
Copy link

forthrin commented Jul 7, 2020

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?

@petdance
Copy link
Collaborator

petdance commented Jul 7, 2020

Can you give a specific command line that you're having problems with?

Does the -h not do what you want?

@forthrin
Copy link
Author

forthrin commented Jul 8, 2020

-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.

@petdance
Copy link
Collaborator

petdance commented Jul 8, 2020

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.

@forthrin
Copy link
Author

forthrin commented Jul 9, 2020

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.

@n1vux
Copy link
Contributor

n1vux commented Aug 12, 2020

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.)

@n1vux
Copy link
Contributor

n1vux commented Aug 12, 2020

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.

@n1vux
Copy link
Contributor

n1vux commented Aug 12, 2020

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 beyondgrep/website#103 )

@ghost
Copy link

ghost commented Jun 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants