Skip to content
Advertisement

Understanding the behavior of grep [closed]

I am under mac os X and I want to find some words in the documentation of Homebrew.

This is a part of the documentation (man brew): enter image description here

I tried this command

JavaScript

and it worked well, below the result:

JavaScript

This command

JavaScript

instead did not produce any output. So I tried to use

JavaScript

but it did not work too.

I want to use grep to find the word ‘leaves’ inside the documentation of Homebrew and print the nearest lines to be able to understand what this option mean. I know that maybe it is a stupid error but I am not able to figure out where it is. Can someone help me?

Advertisement

Answer

The problem is not with grep so much as with man. When you view a manual page, formatting codes are interspersed in order to make the text appear bold (or underlined, etc).

JavaScript

The traditional workaround is to filter formatted output through colcrt:

JavaScript

… but the resulting text is kind of crudely forced to ASCII only. A better solution for most people is to use LESS as your manual pager.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement