Skip to Content.
Sympa Menu

baslinux - [BL] Man2text2 Sed Scripts for Nroff

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: Lee Forrest <lforrestster AT gmail.com>
  • To: baslinux AT lists.ibiblio.org
  • Subject: [BL] Man2text2 Sed Scripts for Nroff
  • Date: Fri, 5 Jan 2007 14:24:20 +0000

This is from the sed&awk book. I haven't tested it
because the only manpages I have are not in nroff.

s/.^H//g
s/^[9//g
s/^[ ^I]*//g
s/^I/ /g

That ^[ (Esc) is made by holding down Ctrl and hitting v then [
in vi-like editors.

For the ^I (Tab), use i instead of [.

For the ^H (Backspace) use h.

The ^[ in the third line is not a control character,
but rather a literal ^[, positioning the regex at the beginning
of a line and starting a bracket expression.

You'd write the above script in a seperate file with vi and do:

sed -f file manpage > outputfile

Nroff manpages look like this in vi (but not less or with cat,
because those ^? control characters are non-printing):

^[9 N^HN^HN^HNA^HA^HA^HAM^HM^HM^HME^HE^HE^HE
who - who is on the system?

S^HS^HS^HSY^HY^HY^HYN^HN^HN^HNO^HO^HO^HOP^HP^HP^HPS^HS^HS^HSI^HI^HI
^HIS^HS^HS^HS
who [-a] [-b] [-d] [-H] [-l] [-p] [-q] [-r] [-s] [-t] [-T]
[-u] [_^Hf_^Hi_^Hl_^He]
who am i

who am I

D^HD^HD^HDE^HE^HE^HES^HS^HS^HSC^HC^HC^HCR^HR^HR^HRI^HI^HI^HIP^HP^HP
^HPT^HT^HT^HTI^HI^HI^HIO^HO^HO^HON^HN^HN^HN
who can list the user's name, terminal line, login time,
elapsed time since activity occurred on the line, and the

[delete]

How you make and view the control characters with emacs-like
editors, I haven't a clue.

/quote

[From the files that were made for the book (obtained from an FTP
server)]

Here's another sed script for the same purpose I picked up
somewhere:

s/.^H//g
s/^M//g
s/^[//g
s/^G//g

Perhaps for one of the nroff variants like groff(?). It worked
pretty good the few times I used it, a long time ago.

This removes all consecutive blank lines, except for one at the
end:

/./,/^$/!d

Add it to either of the sedscript files above. (That ^$ is not
a control character. It's a regex meaning "blank line".)

---------------
This is an example of a troff man page, an entirely different
formatting language:

.\" "%W% %G%"
.TH NETWATCH\ 0.7 0
.SH NAME
Netwatch \- Ethernet Internet Protocol Monitor
.SH SYNOPSIS
.B netwatch
[ -h ] [ -e ethnum ] [ -c netconfigfile ]
.SH DESCRIPTION
.I Netwatch
examines all the packets travelling on an ethernet and analyses the I
P
packets. The information is tallied according to the source and desti
nation
hosts. An
.I "ncurses"
display indicates a dual-list status for all hosts. The
left display refers to LOCAL hosts. The right list refers to REMOTE h
osts.
It is possible to examine statistics (counts) on number of packets,
bytes, IP service type and last communication host for each host. Use
the
arrow keys (left and right) to change the display.
.TP
.SH OPTIONS
.TP
.B \-e ethnum
.B ethnum

/quote

I wrote a crude script using sed that reformats them, and will be
doing some work on it. Search "man2text1.sh" in the archives.

Lee

--
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru





Archive powered by MHonArc 2.6.24.

Top of Page