Gentoo Archives: gentoo-user

From: ABCD <en.ABCD@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: How to get plain ascii from "man"?
Date: Sun, 29 Mar 2009 17:14:59
Message-Id: gqoa9n$1kt$1@ger.gmane.org
In Reply to: Re: [gentoo-user] How to get plain ascii from "man"? by Walter Dnes
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA1
3
4 Walter Dnes wrote:
5 > On Wed, Mar 25, 2009 at 10:12:20PM +0000, Grant Edwards wrote
6 >> How do you get a plain ascii file (no backspacing, no escape
7 >> sequences) out of "man"? Running it through col or colcrt
8 >> doesn't work anymore, because the default output contains ANSI
9 >> color escape sequences.
10 >
11 > I done it! And no, the following "man2text" script is not brought to
12 > you via an uncorrected dialup modem<g>.
13 >
14 > #!/bin/bash
15 > sed "s/^[\[[^m]\+m//g"
16 >
17 > *IMPORTANT* the 8th and 9th columns of the second line are *NOT* "^[".
18 > That's actually the <escape> character as displayed in vim. In vim in
19 > entry mode, you can insert control character by prefixing them with
20 > CTRL-V. To enter the <escape> character, press CTRL-V and release, then
21 > press escape.
22 >
23 > Here's the logic
24 > - You want to get rid of all ANSI terminal sequences
25 > - all ANSI terminal sequences start with <escape>[, have 1 or more
26 > mode characters, and finish off with "m"
27 > - the sed one-liner deletes all such occurences (technically, it
28 > replaces them with nothing).
29 >
30
31 Even better would be, as it avoids a call to bash:
32
33 #!/bin/sed -f
34 s/^[\[[^m]\+m//g
35
36 (with the same "^[" is really ESC)
37
38 - --
39 ABCD
40 -----BEGIN PGP SIGNATURE-----
41 Version: GnuPG v2.0.11 (GNU/Linux)
42 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
43
44 iEYEARECAAYFAknPrAoACgkQOypDUo0oQOrVYwCfZ/f8eaFpMy0E8+fs96qCG3Dv
45 mscAoLAdGesfNBz3EsRp7aaqUiBwjpeo
46 =qUzQ
47 -----END PGP SIGNATURE-----