If I do a plain ack for a string, I get a line with the filename, and then the line numbers and the matching lines, like so:

$> ack function
8: function myfunction1() {
16:  public function __construct( $protocol = 'ftp') {
36:  public static function getSupportedProtocols() {

However, when I ack the results for a second string, the lines come out with more information on a single line:

$> ack function|ack test
mymodule.file:897:function mytest() {

I noticed this also happens when grepping the results of ack.

How is the information on various lines being reduced to one line? Is it the shell doing this?


This is done by ack itself. ack checks if its standard output is connected to a terminal, and if it isn't, it prints output in a different format. I guess this format was chosen because it is more easy to process by applications designed for text processing (like grep or ack itself).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.