Re: suppressing the line number in output

6,547 views
Skip to first unread message

Matt

unread,
Jul 21, 2010, 4:55:35 PM7/21/10
to ack dev/users
From thread http://groups.google.com/group/ack-users/browse_thread/thread/c92ce0581bf6c7dd
...
On Jun 21 2008, 8:58pm I wrote:
> Is there any way to suppress the line number from the search output?
> Apparently not, according to my quick read of the code; looks like
> when $show_filename is true the line numbers will always be printed.
>
> I have a specialized search tool that currently uses GNU egrep which
> I'd like to adapt for ack, but I don't want line numbers in my output.
> (But I *do* want the filenames in the output.) I suppose I can strip
> them out by post-processing but it would be convenient if there was an
> ack option to suppress them.
>
> [ later in the thread I suggested the option --no-line-number for this ]

In response to that I just received a "me too" email from Jason
Tholstrup:

> I know this is old but I would also like to suppress line number
> output. This is good for piping into a sort uniq to find unique lines.
>
> Thanks,
> Jason Tholstrup

Jason makes a good point. I use grep in this way all the time:

grep "GET / " httpd-access.log | awk '{print $1}' | sort | uniq -c |
sort -rn

to generate a client address count report of HTTP accesses of the
front page of my website.

To do this using ack, I would have to add a 'sed' statement to the
pipeline to strip off the matching line numbers to enable uniq -c to
count the duplicated lines.

So, a --no-line-number option to ack would be handy in this case.

Thanks,
Matt

Jason

unread,
Jul 21, 2010, 5:12:40 PM7/21/10
to ack dev/users
Thanks Matt for posting this. Since there was not "reply" in the old
thread I hit "reply to author" instead thinking that would post
instead of emailing you. Anyway I think this would help in letting
ack be a drop-in grep replacement in more situations. I might also
suggest the flag be

-s --suppress_line_numbers

Since -n is already taken.

Jason Tholstrup

Rich Jones

unread,
Sep 1, 2010, 3:15:11 PM9/1/10
to ack dev/users
I realize this is super late in the discussion, but I came here
looking for this information and was saddened to see there's no way to
suppress line numbers in ack. I often use ack -C to find reusable
chunks of code from other projects, but I can't copy and paste them
directly because of the line numbers in the output. ack -C -s would be
absolutely killer for me, please consider adding it!

Also, thanks for the wonderful tool
Rich

Aaron Culich

unread,
Sep 1, 2010, 3:43:00 PM9/1/10
to ack-...@googlegroups.com
Hi Rich,

Actually, funny you mention that... a couple days ago I wanted that same feature in ack, as well, so modified the code to default to grep's standard behavior (which is to NOT show line numbers) when you run ack with the --nogroup option or if you run it non-interactively (which implies --nogroup). I submitted a pull request on github, but Andy suggested I write to the list here to get opinions before he accepts a patch that changes ack's expected behavior. And, of course, like grep you can add the -n to turn on the line numbers. I realize I should probably add an option that would allow you to suppress line numbers even when grouping is turned on, but for now you can check out my changes here:


-Aaron


--
You received this message because you are subscribed to the Google Groups "ack dev/users" group.
To post to this group, send email to ack-...@googlegroups.com.
To unsubscribe from this group, send email to ack-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ack-users?hl=en.


Reply all
Reply to author
Forward
0 new messages