UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 6: File Management |
|
||||||||||||||||||||||||||||||||||||
|
There is a way to strip out all nonessential escape characters to make the man pages more readable.
Flavors: AT&T, BSD
Syntax:
man - [manpage] | col -b > [file]
The man pages are extremely useful for learning commands and functions. They can be manipulated depending on the arguments passed to them. If all the escape sequences that are embedded within the man pages are too difficult to interpret by the terminal, there is a way to convert a man page into simple text. If you want to view the tar man page within the vi editor, you normally would take the following steps.
rocket 60% man tar > /usr/tmp/tar.man
Redirect the output of the man pages to the a file so that you can run the editor on it.
rocket 61% vi /usr/tmp/tar.man
When the file is edited with vi, the file becomes too cryptic with all the escape sequences that are passed to the file.
tar(1) User Commands tar(1)
NAME tar - create tape archives, and add or extract files
SYNOPSIS /usr/sbin/tar c [ bBefFhilvwX [ 0-7 ]] [ _^Hd_^He_^Hv_^Hi_^Hc_^He ] [ _^Hb_ ^Hl_^Ho_^Hc_^Hk ] [ _^He_^Hx_^Hc_^Hl_^Hu_^Hd_^He-_^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ... ] [ -I _^Hi_^Hn_^Hc_^Hl_^Hu_^Hd_^He-_^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ] _^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ... [ -C _^Hd_^Hi_^Hr_^He_^Hc_^Ht_^H o_^Hr_^Hy _^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ] /usr/sbin/tar r [ bBefFhilvw [ 0-7 ]] [ _^Hd_^He_^Hv_^Hi_^Hc_^He ] [ _^Hb_^ Hl_^Ho_^Hc_^Hk ] [ -I _^Hi_^Hn_^Hc_^Hl_^Hu_^Hd_^He-_^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ] _ ^Hf_^Hi_^Hl_^He_^Hn_^Ha_^Hm_^He ...
To clean up all the escape sequences, run them through the col program. When the man pages are piped through the col command, the escape sequences are stripped by applying the -b option. So this time when the tar man page is redirected to a file and then brought into the vi editor you can see plain text.
rocket 62% man - tar | col -b > /usr/tmp/tar.man rocket 63% vi /usr/tmp/tar.man
tar(1) User Commands tar(1)
NAME tar - create tape archives, and add or extract files
SYNOPSIS /usr/sbin/tar c [ bBefFhilvwX [ 0-7 ]] [ device ] [ block ] [ exclude-filename ... ] [ -I include-filename ] filename ... [ -C directory filename ]
/usr/sbin/tar r [ bBefFhilvw [ 0-7 ]] [ device ] [ block ] [ -I include-filename ] filename ... [ -C directory filename ]
Sometimes you might come across a terminal that is foreign to the system; if you need to reference the man pages, they are illegible.
There are other instances when you might want to convert the man pages into straight text. If you are putting together documentation for operators or for policy, you might need to reference certain man pages that exist in the system. The only way to pass this data into the document is to strip the escape sequences to make the word processor or editor understand it and print correctly.
Another use for converting the man pages to straight text is to turn the man pages into Web pages. This simple script is called htmlmake. When you run it in a man page directory, it generates the Web pages for you:
# vi /usr/local/bin/htmlmake
#! /bin/sh for i in $* do MAN=`echo $i | cut -d"." -f1` echo "$i" echo "<TITLE>$i</TITLE>" > /httpd/htdocs/man/$i.html echo "<HTML><PRE>" >> /httpd/htdocs/man/$i.html man - $MAN | col -b >> /httpd/htdocs/man/$i.html echo "</PRE></html>" >> /httpd/htdocs/man/$i.html done
Line 1: Define the shell to be used for the script.
Line 2: Begin processing the directory with the files that are passed to the script.
Line 4: Get the name of the man page.
Line 5: Display which man page is being processed.
Line 6: Write out the title of the Web page to the HTML file.
Line 7: Write out the beginning of the Web page format data to the HTML file.
Line 8: Strip out the escape sequences and write out the data to the HTML file.
Line 9: Write out the end of the Web page data to the HTML file.
Line 10: Do the next file until all the files in the directory have been processed.
Here is a sample of the information when the file is run against the man pages for newaliases:
# htmlmake newaliases.1 newaliases.1
# cat /httpd/htdocs/man/newaliases.1.html
<TITLE>newaliases.1</TITLE> <HTML><PRE>
newaliases(1M) newaliases(1M)
NAME
newaliases - rebuild the data base for the mail aliases file
SYNOPSIS newaliases
DESCRIPTION newaliases rebuilds the random access data base for the mail aliases file /etc/aliases. It must be run each time /etc/aliases is changed in order for the change to take effect, unless sendmail has been configured to automatically rebuild the database, which is the default.
SEE ALSO sendmail(1M), aliases(4).
</PRE></html>
The result is a perfectly simplified Web page on a man page that can be applied to an intranet or Internet Web site.
col, man
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 6: File Management |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.