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