6

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?

2 Answers2

6

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
  • 162,382
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