Show line number when search a single file

5

ack usually shows line numbers with file name,

$ ack searchme
filename
1:searchme

but it doesn't when search a single file,

$ ack searchme filename
searchme

It's easy to show line numbers with grep

$ grep -n searchme filename
1:searchme

Can I show the line numbers when I search a single file with ack?

Sanghyun Lee

Posted 2014-11-12T08:59:35.807

Reputation: 270

Answers

5

This issue was raised as a bug for ack Output line numbers of matches when acking a single file #244 with the following response:

All future development on ack is happening on https://github.com/petdance/ack2. This issue has been moved here: Do we need an option for forcing the printing of the line number? #196

The status of the ack2 request is open.

Output line numbers of matches when acking a single file #244 does include a patch which may resolve the issue as well as the following comment:

Nevertheless using --with-filename option will always print file name and therefore line numbers.

DavidPostill

Posted 2014-11-12T08:59:35.807

Reputation: 118 938

3

You can append "more" to your command and it will display the file name and line numbers for each result

Example:
ack test test.c more test.c
12: something here that had test
17: something here that had test
32: something here that had test

itsfunshine

Posted 2014-11-12T08:59:35.807

Reputation: 31