Contributions

Open Source sticker

Toutes les contributions de Pragmatic Source, que ce soit sous forme d'articles, de présentations ou de code sous licence libre, sont disponibles dans cette section du site et sur notre Référentiel Open Source (Redmine).

All of our contributions (articles, slideshows, Open Source code) are available in this section and on our Open Source Repository (Redmine).

Remove bold and underline attributes (overstrike) from a text or a manpage

Under Unix/Linux, commands like « man » output texts containing bold and underline attributes, even in console mode. These attributes are produced by inserting a combination of control characters (« Backspace » or « ^H ») and underscores (« _ ») after the characters to highlight.

Sometimes you need to remove these overstrike control characters.

To do this, you can use the following command line:

  1. sed -e 's/_^H//g' -e 's/^H.//g' -e 's/^[\[[0-9]*m//g' < infile.txt > outfile.txt

Or under Vim type the two following commands:

  1. :%s/_^H//g
  2. :%s/^H.//g
  3. :%s/^[\[[0-9]*m//g'

And it's done!

Beware : In order to type the ^H control char on the command line prepend it with your shell's escape character, for example « Control-V + Control-H » under Zsh and Vim.