-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

Even better would be, as it avoids a call to bash:

#!/bin/sed -f
s/^[\[[^m]\+m//g

(with the same "^[" is really ESC)

- --
ABCD
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknPrAoACgkQOypDUo0oQOrVYwCfZ/f8eaFpMy0E8+fs96qCG3Dv
mscAoLAdGesfNBz3EsRp7aaqUiBwjpeo
=qUzQ
-----END PGP SIGNATURE-----


Reply via email to