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?

  • 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 7 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 <xxx> | col -b | grep -A2 "SEE ALSO" – user361195 Jul 7 at 12:37
  • This seems to be unix.stackexchange.com/questions/271550/…; the man page appears to me to come out as S^HSE^HEE^HE A^HAL^HLS^HSO^HO – Jeff Schaller Jul 8 at 0:09
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
  • 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 7 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 7 at 14:45

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.