0

When I'm grepping a man page for the section titles written in capitals, it seems as if they are not there. It works with the same words in lowercase. For example, when I write man <xxx> | grep -i also, it shows all the lines with the word "also" but not "SEE ALSO" section title.

How can I make grep recognize section titles of man pages?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • 1
    Can you give an example of this failing? I can't reproduce what you describe. What do you get for man ls | grep -A2 ALSO? What operating system are you using? – terdon Jul 07 '19 at 12:22
  • 1
    I'm using OpenBSD and I get nothing.

    Anyway, I've solved it - between first and second command add another pipe - | col -b or | ul - so it becomes:

    man | col -b | grep -A2 "SEE ALSO"

    – user361195 Jul 07 '19 at 12:37
  • This seems to be https://unix.stackexchange.com/questions/271550/how-can-i-search-for-bolded-or-underlined-text; the man page appears to me to come out as S^HSE^HEE^HE A^HAL^HLS^HSO^HO – Jeff Schaller Jul 08 '19 at 00:09

1 Answers1

0

I don't have a BSD system to check on, but there are probably more whitespace characters than you expect between the SEE and the ALSO. Try one of these instead:

man foo | grep -A2 'SEE.*ALSO'
man foo | grep -A2 'SEE\s*ALSO`

or even, since it's unlikely there will be any other occurrences of capitalized ALSO, just:

man foo | grep -A2 ALSO
terdon
  • 242,166
  • Hey, thanks for your reply. It didn't work for "ALSO", neither for "FILES" section of the man page - but it could find all those words in lowercase. Anyway, I solved it already by myself and posted a solution above. – user361195 Jul 07 '19 at 14:42
  • @user361195 if you really want to use that approach (which is more complex than necessary, the best solution would be to check what non printing characters you have there, run grep SEE | od -c or something), please post it as an answer and not a comment. That way, you can accept it and get some rep (if you care about that) but more importantly, the question can be marked as answered. – terdon Jul 07 '19 at 14:45