Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Ack and the grep –color Problem on Windows

📅 2010-Nov-19 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ack, colors, grep, windows ⬩ 📚 Archive

 

grep –color Problem

grep is a very useful tool to have around on Windows. (See this post for information on installing it for Windows.) However, the grep --color parameter does not work with the Windows command console. When looking for a search string in long lines, the need for color becomes crucial. Sadly, there is no grep clone for Windows that does color output.

Ack Installation

A good solution for these cases is to use Ack. It is a modern rival of Grep and claims to be better. (Its webpage is betterthangrep.com! ;-) ) It is written in Perl.

If you do not have Perl, you need to install Strawberry Perl. Install Ack using the command cpan App::Ack. This might exit with a few warnings. To force it to install Ack anyway use cpan -f App::Ack.

Once Ack is installed, it can be used just like grep. For example:

$ set | ack -i processor

Enabling Color for Ack

You will notice that Ack does not display the matched string in color. It does not need a --color parameter since it uses color by default. However, to gain access to the color output capability on Windows, it needs some help. Install the following from CPAN:

$ cpan Win32::Console::ANSI

Ack will highlight the matched strings in color after this! 😊


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧