Hi Morten,

At 2026-02-23T15:21:09+0100, Morten Bo Johansen wrote:
> Meanwhile, I think I have found a solution. To search for e.g. the
> "am" request in man 7 groff from the command line or from a function,
> one could do:
> 
>   man 7 groff | less -c +/"[^a-zA-Z0-9]am[^a-zA-Z0-9]"
> 
> this could seem like an attempt at simulating word boundaries, but of
> course this expression would normally fail if "am" was at the
> beginning or the end of a line. The thing is that it never is, in this
> context. There will always be either some white space or some control
> characters before and after the search string, and therefore the
> matching will always succeed. I believe that the pagers do their
> matching on the raw output from the "man" command which may be seen
> with e.g "man 7 groff_ms | cat -A | less". At the beginning of the
> line, there will always be spaces and the end of the line will always
> be seen by less as "$". At least this is my understanding of why this
> works. You may of course want to set me aright.

Looks good to me.  Here it is as a shell function you can put in your
.bashrc (or startup file for some other POSIX shell).

    # Search for a word in a given man page.
    #
    # Equivalent examples (if using man-db man): tagman am 7 groff
    #                                            tagman am 'groff(7)'
    #                                            tagman am -s 7 groff
    tagman () {
      word=$1
      shift
      man "$@" | "${PAGER:-less}" -c '+/[^a-zA-Z0-9]'"$word"'[^a-zA-Z0-9]'
    }

Regards,
Branden

Attachment: signature.asc
Description: PGP signature

Reply via email to