5

In linux the grep output gets highlighted in red. Is there any special command to achieve the same using findstr in Windows cmd?

I am trying this command in cmd - adb logcat -v time | findstr /a:color [4] \"NETWORK" but in return it says specify only /L or /R.

(While Googling I learnt that /a is for color formatting and 4 stands for Red color)

I need to search for "NETWORK" calls my Android app is making. To view the logs better, it would be helpful if the output of findstr gets colorized.

Sudar
  • 59
  • 1
  • 3
  • 1
    Type `findstr /?` and see. –  Nov 04 '16 at 08:33
  • What happens when you only use '/a:04' and leave the string 'color' out ? – Marged Nov 04 '16 at 08:40
  • Remove the backslash in front of `"NETWORK"`; otherwise the opening `"` becomes part of the search string... – aschipfl Nov 04 '16 at 10:10
  • 4
    `findstr` does not colour its complete output, the `/A` switch is applied to preceding line numbers (`/N`) or file names (if multiple files are given) only; take a look at this great post to learn more: [How to have multiple colors in a Windows batch file?](http://stackoverflow.com/a/5344911) – aschipfl Nov 04 '16 at 10:19
  • 1
    Using `findstr` in Windows is like taking [a step back](https://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) to the DOS era. You're simply better off writing your own parser from scratch. Install Cygwin and be happy. – not2qubit Dec 10 '18 at 15:46

1 Answers1

2

You can use the color attribute as follows findstr /s /n /a:e /i "<your search string>" <file paths>. Note that /a:<color code> is the option you are looking for. Here's an example:

findstr with color example

Here are the list of colors available. I am using 'e' or 'E' or 'Light Yellow':

Colors available in cmd

user3613932
  • 861
  • 11
  • 14
  • Well, but this behaves differently from grep. Grep is printing lines which contain the text you are searching for as `findstr` is doing but it's highlighting the searched text. `findstr` is kind of useless for me because without such highlighting, I have to manually read each line anyway and find where's the searched text. – David Ferenczy Rogožan Aug 24 '18 at 16:34
  • 3
    To be clear, this is not the answer. Linux's `grep` command colorizes the matching string in output text whereas Windows' `findstr` command's `/a:` flag only colorizes the output headings generated when the `/n` (line number) or `/s` (filename) flags are specified. – Patrick Dark Jun 02 '19 at 18:30
  • Happy to update if newer version of findstr supports highlighting the searched expression like grep. This is the best findstr could do as per my research when this was posted. – user3613932 Jul 07 '20 at 03:21