1 |
On Wed, Mar 25, 2009 at 10:12:20PM +0000, Grant Edwards wrote |
2 |
> How do you get a plain ascii file (no backspacing, no escape |
3 |
> sequences) out of "man"? Running it through col or colcrt |
4 |
> doesn't work anymore, because the default output contains ANSI |
5 |
> color escape sequences. |
6 |
|
7 |
I done it! And no, the following "man2text" script is not brought to |
8 |
you via an uncorrected dialup modem<g>. |
9 |
|
10 |
#!/bin/bash |
11 |
sed "s/^[\[[^m]\+m//g" |
12 |
|
13 |
*IMPORTANT* the 8th and 9th columns of the second line are *NOT* "^[". |
14 |
That's actually the <escape> character as displayed in vim. In vim in |
15 |
entry mode, you can insert control character by prefixing them with |
16 |
CTRL-V. To enter the <escape> character, press CTRL-V and release, then |
17 |
press escape. |
18 |
|
19 |
Here's the logic |
20 |
- You want to get rid of all ANSI terminal sequences |
21 |
- all ANSI terminal sequences start with <escape>[, have 1 or more |
22 |
mode characters, and finish off with "m" |
23 |
- the sed one-liner deletes all such occurences (technically, it |
24 |
replaces them with nothing). |
25 |
|
26 |
-- |
27 |
Walter Dnes <waltdnes@××××××××.org> |