Oddness in ack (betterthangrep.com) – Sometimes I get a line number, sometimes not.
In the first example, I look for a simple phrase in some Python files.
It works fine, and shows line number 233.
In the second example, I look for all lines where the first column ends with ‘5’.
D:\DSWProj\2012L\src> perl D:\ack-standalone.pl "return True" *.py
Volume5.py
233: return True
D:\DSWProj\2012L\data\R123> perl D:\ack-standalone.pl "5 " NeedMoreCoffee_n5_*.data
Volume5 FooData coffee_n5 2013-01-29 10:14
397125 0 0 1 0
397135 0 0 1 0
Those two lines are exactly the first two lines in the file following the header line.
Why are there no line numbers in this second example? There’s also no file name printed, and no colorization. The Python example does colorize output – the line numbers are yellow, file names green. (A surprise, since the last time I asked, was told Windows command line shell can’t colorize anything at all.) Is this a bug in ack, or quirk of Windows? Did I do something unwittingly different between the two cases, besides the obvious searching for different things in different files?
Running on Windows 7 64-bit, using Strawberry Perl 5.16.2 downloaded two days ago (January 28th, 2013),
and ack standalone script, ver 1.96, downloaded also two days ago.
I believe
ackmagically* knows that*.pyfiles are Python source code, and will show line numbers and colorization for source code files but not for plain old data files like*.data. This is considered a feature, not a bug.If you want a predictable, composable replacement for
grep, trygrep. 😉* – It’s not really magic, of course; it’s configurable in your
.ackrcfile. Runack --help-typesfor more information.EDIT: I’m wrong! It’s not because of the difference between
.pyand.data; it’s because of the difference betweenack pattern f1andack pattern f1 f2 .... In the latter case,ackwill print which of the filesf1 f2 ...contained the matches; in the former (single file) case,ackwill behave more likegrep.To fool
ackinto producing line numbers even for a single file, add a fake file on the end of the line. For Cygwin, you could probably doFor Windows, maybe this still works:
(that’s literally the letters N U L, which is how Windows spells
/dev/null; see also CON, LPT1, etc).