SUMMARY: Processing of text

From: Wyatt Song <wyatt.song_at_veritas.com>
Date: Tue Oct 08 2002 - 21:40:28 EDT
Thanks for all the help! The following people provided good insight which
allowed me to learn a lot. The solutions are listed, and they illustrate the
possibility of using different approaches to the same problem.
 
Thanks
Wyatt
 
====== Acknowledgement ======
John Leadeham [jl@lammtarra.fslife.co.uk]
Scott Howard [scott@doc.net.au]
Steve Sandau [ssandau@bath.tmac.com]
Mark Donaldson [Mark.Donaldson@experianems.com]
Fabrice Guerini [fabrice@life.net]
Baumler Julie L [julie.x.baumler@co.multnomah.or.us]
 
======== Solution 1 =========
set the environment variable PAGER to less, less takes options (either -p or
/ iirc) to search for a particular pattern on startup, so you could have a
script/alias/shell-function called manalso or ma that does
    PAGER="less -p'SEE ALSO'" man whatever
 
OLE_LINK1======== Solution 2 =========
perl -e '$/="\0"; $_=<>; print $1 if (m/^(DESCRIPTION.*?)^[A-Z]{5}/ms);'
 
That will print from the title given (eg, DESCRIPTION in this case) up
to the start of the next section (in particular, the next line which has at
least 5 uppercase chars at the start of the line).
 
eg
 
[18:26:23][@milliways /tmp]$ man printf | perl -e '$/="\0"; $_=<>; print $1
if (
m/^(DESCRIPTION.*?)^[A-Z]{5}/ms);'
Reformatting page.  Please Wait... done
DESCRIPTION
     The printf command writes formatted operands to the standard
     output. The argument operands are formatted under control of
     the format operand.
 
OLE_LINK2======== Solution 3 =========
'man' command invokes a paginator on its own; you do not need to call less
explicitly. running 'man awk' and then hitting '/' to search and typing the
text you want to search for will work.
 
As for a more elegant solution, there is a way to runn troff or nroff to
reformat the page wihout the inclusion of a paginator. You could then pipe
the output of that to sed and ask it to display the text beginning with the
section you want to view:  'nroff -???? /usr/man/sman1/awk.1 | sed -n /"SEE
ALSO"/./$/p | less'
 
OLE_LINK3 
======== Solution 4 =========
awk 'BEGIN {flag=0} 
     { if ( $0~/STARTPAT/ ) {flag=1} 
       if ( $0~/ENDPAT/ )   {flag=0} 
       if ( flag==1 ) {print} }  ' inputfile 
This'll print the lines between STARTPAT and ENDPAT for the inputfile. 
the "STARTPAT" line is included in the output but the "ENDPAT" line is not.
you can include the ENDPAT line by moving it below the print line if you
wish.
 
======== Solution 5 =========
man ls | sed -e 's/.^H//g' | sed -e '1,/SEE ALSO/d' -e '/^[A-Z]/,$d'
(make sure to replace the "^H" with an actual backspace)


======== Solution 6 =========
I like to read the special install instructions in patches (which is usually
the last thing there) to do so, I use the following command:
 
sed -n '/Special Install Instructions:/,$ p' <file>
 
For a man page, if you wanted to read from pattern1 (ie. SEE ALSO) to
pattern 2 (ie. NOTES), you could do the following:
 
man cmd | sed -n '/pattern1/,/pattern2/ p' 
 
Or in your case:
 
man ls | sed -n '/SEE ALSO/,/NOTES/ p'
 
This does include the line that says NOTES, you can do some further
scripting to remove that, but this is short enough to remember.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue Oct 8 21:43:12 2002

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:56 EST