Re: Inconsistent macro notation in manual pages.

"G. Branden Robinson" <[email protected]>
Newsgroups gmane.comp.printing.groff.general
Message-ID <20260228044643.vqeszols5et6m6ui@illithid>
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
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEh3PWHWjjDgcrENwa0Z6cfXEmbc4FAmmicysACgkQ0Z6cfXEm
bc57ww//Z0rLHfjZl3j6Id4vjtkSaYsOxP0moJh2N4xT9NZ0MdbjH1OjUeyIfiMj
aMT9bXeSImhdht/fixnmZi4jfYM2OUsh189JhRsD0Hx9UeidryMBEe6wp7s1aOw0
aKIEePnaftuyast34Bco9UxlXMP4ShOBvwExz7gn+Sssm6/VhtfH7ubxN2QaM/w6
MqU4EI3Iyd3bfl/C/+ffAjyvbKa+1QeJXnU+fpmEZjsIwgn0FnDjmvYFL/QY726t
xJcXBcvvQLCLK2JuK+I6pt/cqpGsyxZeBBHWG0YsgEvTYG68dHNu+rscDD2CqlzI
CBKNT98WvRo+Jb90n8qypwgoHqNVVCcAhl2XzqIXrHEprgS09zGJQ/Pb5l1Nh3qL
rIp95HCj7p5nshci//Lw28dF7XPNLoLQtcq6ZO02hIAMFWILzEr7rIuarT5GKFGo
TdHTR9COBPqQHCKKDSMZi+Gg0CWnClQkG/Sacy4XsW9jrsnm3KuRlBtXd/Smr7p+
0/YD+ahTnaQEp8Nc7hTBMWvEcXryVr8VPsf4b/1Er0U3pWgTpKMukBIEuxFtz1E0
71O8+hx1oMh9RxSV9EGb0YFkiPaq0PgadexMym5zH3grBFNJm78+MicHArqWm6NB
YytXOBSEWHSwd9W/dxhfJatkBOqQIcEscmJX4e64m0NjPy/SrNk=
=4yfc
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.