[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Parsing specific section of man page
From: |
Anton Shepelev |
Subject: |
Re: [Groff] Parsing specific section of man page |
Date: |
Tue, 24 Jan 2012 12:02:15 +0400 |
Vannevar Bush:
> It parses and shows me the whole page. What if I
> want to parse only OPTIONS section ? I am looking
> for something like :-
>
> groff -X -P -resolution -P100 -man -parse-section "OPTIONS" passwd
Here is my quick, dirty and incomplete solution:
.nr skip 0u \" Flag to indicate whether the current text is to be skipped
.am TH \" Have to append .TH, because the man macros are initialized
. \" inside .TH
.
. de scls end \" Couldn't make this part work:
. br \" Can't covert a diversion to a string
. di \" usable for comparison with the current title
. in
. ds sectxt \\\\*[secn]\"Collecting the input line after call to SH
. SH-N \\\\*[sectxt]\"and passing ti to SH-N as parameter.
. end
. rn SH SH-orig \" Rename the original SH so as to prepend it.
. de SH end \" The definition of the new SH
. ie '\\\\$*'' \{\\"Title given on the next input line
. in 0
. it 1 scls \"Input trap to capture the next input line
. di secn \"Inside this diversion
. \}
. el .SH-N \\\\$* \" Title given as parameter
. end
.
. de SH-N end
. nr b-print 0
. if '\\\\*[secf]'' .nr b-print 1
. if '\\\\*[secf]'\\\\$1' .nr b-print 1
. ie \\\\n[b-print] \{\
. if \\\\n[skip] \{\
. nr skip 0
. br
. di
. ch devnull
. \}
. SH-orig \\\\$*
. \}
. el \{\
. if !\\\\n[skip] \{\
. nr skip 1u
. br
. di devnull
. \}
. \}
. end
..
.TH 1 Title
.SH One
Text of section One
.P
Another paragraph
.SH Two
Text of section Two
.SH Three
Text of section Three
See how it works by processing the file with groff:
Print whole file:
groff -Tascii -man secfilter.man -P-cbu> secfilter.txt
Print individual sections:
groff -Tascii -man -dsecf=One secfilter.man -P-cbu> secfilter.txt
groff -Tascii -man -dsecf=Two secfilter.man -P-cbu> secfilter.txt
groff -Tascii -man -dsecf=Three secfilter.man -P-cbu> secfilter.txt
Anton
- Re: [Groff] Parsing specific section of man page, (continued)
- Re: [Groff] Parsing specific section of man page, Siteshwar Vashisht, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Ingo Schwarze, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Clarke Echols, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Ralph Corderoy, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Ted Harding, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Ingo Schwarze, 2012/01/22
- Re: [Groff] Parsing specific section of man page, Ralph Corderoy, 2012/01/22
- Re: [Groff] Parsing specific section of man page, James K. Lowden, 2012/01/24
- Re: [Groff] Parsing specific section of man page, Charlie Kester, 2012/01/24
Re: [Groff] Parsing specific section of man page, Larry Kollar, 2012/01/22
Re: [Groff] Parsing specific section of man page,
Anton Shepelev <=
Re: [Groff] Parsing specific section of man page, ridiculous_fish, 2012/01/23