# grep and manpages



## sidetone (May 31, 2018)

Can I use `grep` and textproc/bsdgrep to locate underlined words including headers within manpages? So far it can get search for any header not underlined within that manpage.
The headers can be included in the search with A (after) and B (before) options. The `-i` (case) argument didn't work either for locating underlined headers.

`man rc.conf | grep -A2 -B2 kld_list`.


----------



## tobik@ (May 31, 2018)

Strip the escape sequences first:
`man rc.conf | col -b | grep -A2 -B2 kld_list`

What are you trying to do?


----------



## VladiBG (May 31, 2018)

Instead of using grep to filter the content in the man page you can open the man page then use internal search function of the "more or less pager". For example if you are searching for "kld"
open the man page `man rc.conf`
type /kld inside the man page hit enter this will search for the first match of "kld" ( / =
to search for next match press "n"

/pattern          *  Search forward for (N-th) matching line.
  ?pattern          *  Search backward for (N-th) matching line.
  n                 *  Repeat previous search (for N-th occurrence).
  N                 *  Repeat previous search in reverse direction.


Edit: if you are using "less" then the search pattern is highlighted in the entire document. It depend of your default PAGER env.



> Why would someone use "more" if they can use "less"?


----------



## sidetone (May 31, 2018)

Both solutions are good.



tobik@ said:


> Strip the escape sequences first:
> `man rc.conf | col -b | grep -A2 -B2 kld_list`
> 
> What are you trying to do?


Trying to search for the underlined item of any manpage, and what comes after it.
`man rc.conf | col -b | grep -A3 kld`. The -B option was to show of the inconvenient way, that didn't always work, I used it to turned up a category.


----------

