PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Stripping ANSI escape characters from output
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Stripping ANSI escape characters from output

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 12h34   #1
pmaire@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Stripping ANSI escape characters from output

Hi
I have a program, let's call it 'toto', that generates text with color
(ansi escape codes)
I want to keep a log of toto's execution, and display its output with
the colors in real time, so at the moment, I do (in tcsh) :

toto |& tee execution.log

But when I read the log with nedit for example, the color codes
present in the log alter the readability of the file.
I could make a script that strips the escape characters in the log
file after execution, but I would prefer if the escape sequences were
never written in the file, so that no user intervention is needed.

I have an idea : we could pipe the output of toto to sed, but I don't
know if sed is able to print the input data both on the screen
(unaltered) and to a file (with escape chars removed)
Do you have a little trick that could solve my problem ?

Thanks to everyone and have a nice day !
Philippe

  Réponse avec citation
Vieux 06/11/2007, 13h11   #2
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

pmaire@gmail.com wrote:
>
> I have a program, let's call it 'toto', that generates text with color
> (ansi escape codes)
> I want to keep a log of toto's execution, and display its output with
> the colors in real time, so at the moment, I do (in tcsh) :
>
> toto |& tee execution.log
>
> But when I read the log with nedit for example, the color codes
> present in the log alter the readability of the file.
> I could make a script that strips the escape characters in the log
> file after execution, but I would prefer if the escape sequences were
> never written in the file, so that no user intervention is needed.
>
> I have an idea : we could pipe the output of toto to sed, but I don't
> know if sed is able to print the input data both on the screen
> (unaltered) and to a file (with escape chars removed)
> Do you have a little trick that could solve my problem ?


[bash & GNU sed]

echo 123hello | sed -ne "p;s/123//w/tmp/output.txt"
123hello

$ cat /tmp/output.txt
hello

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
  Réponse avec citation
Vieux 06/11/2007, 13h12   #3
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

pmaire@gmail.com wrote:
>
> I have a program, let's call it 'toto', that generates text with color
> (ansi escape codes)
> I want to keep a log of toto's execution, and display its output with
> the colors in real time, so at the moment, I do (in tcsh) :
>
> toto |& tee execution.log
>
> But when I read the log with nedit for example, the color codes
> present in the log alter the readability of the file.
> I could make a script that strips the escape characters in the log
> file after execution, but I would prefer if the escape sequences were
> never written in the file, so that no user intervention is needed.
>
> I have an idea : we could pipe the output of toto to sed, but I don't
> know if sed is able to print the input data both on the screen
> (unaltered) and to a file (with escape chars removed)
> Do you have a little trick that could solve my problem ?


[bash & GNU sed]

$ echo 123hello | sed -ne "p;s/123//w/tmp/output.txt"
123hello

$ cat /tmp/output.txt
hello

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
  Réponse avec citation
Vieux 06/11/2007, 13h12   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

pmaire@gmail.com wrote:
> Hi
> I have a program, let's call it 'toto', that generates text with color
> (ansi escape codes)
> I want to keep a log of toto's execution, and display its output with
> the colors in real time, so at the moment, I do (in tcsh) :
>
> toto |& tee execution.log
>
> But when I read the log with nedit for example, the color codes
> present in the log alter the readability of the file.
> I could make a script that strips the escape characters in the log
> file after execution, but I would prefer if the escape sequences were
> never written in the file, so that no user intervention is needed.
>
> I have an idea : we could pipe the output of toto to sed, but I don't
> know if sed is able to print the input data both on the screen
> (unaltered) and to a file (with escape chars removed)
> Do you have a little trick that could solve my problem ?
>
> Thanks to everyone and have a nice day !
> Philippe
>


toto | awk '{print;gsub(/[[:control:]]/,"")rint > "log";system("")}'

system() flushes the buffer. In GNU awk you could use fflush().

Ed.
  Réponse avec citation
Vieux 06/11/2007, 13h33   #5
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

Cyrus Kriticos wrote:
>
> [bash & GNU sed]
>
> $ echo 123hello | sed -ne "p;s/123//w/tmp/output.txt"
> 123hello
>
> $ cat /tmp/output.txt
> hello


sorry, does not work correct.

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
  Réponse avec citation
Vieux 06/11/2007, 15h42   #6
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

On 2007-11-06, pmaire@gmail.com <pmaire@gmail.com> wrote:
> Hi
> I have a program, let's call it 'toto', that generates text with color
> (ansi escape codes)
> I want to keep a log of toto's execution, and display its output with
> the colors in real time, so at the moment, I do (in tcsh) :
>
> toto |& tee execution.log
>
> But when I read the log with nedit for example, the color codes
> present in the log alter the readability of the file.
> I could make a script that strips the escape characters in the log
> file after execution, but I would prefer if the escape sequences were
> never written in the file, so that no user intervention is needed.
>
> I have an idea : we could pipe the output of toto to sed, but I don't
> know if sed is able to print the input data both on the screen
> (unaltered) and to a file (with escape chars removed)
> Do you have a little trick that could solve my problem ?
>
> Thanks to everyone and have a nice day !
> Philippe
>

toto |& tee /dev/tty | col -b > execution.log
  Réponse avec citation
Vieux 06/11/2007, 16h24   #7
pmaire@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

On 6 nov, 14:12, Ed Morton <mor...@lsupcaemnt.com> wrote:
> pma...@gmail.com wrote:
> > Hi
> > I have a program, let's call it 'toto', that generates text with color
> > (ansi escape codes)
> > I want to keep a log of toto's execution, and display its output with
> > the colors in real time, so at the moment, I do (in tcsh) :

>
> > toto |& tee execution.log

>
> > But when I read the log with nedit for example, the color codes
> > present in the log alter the readability of the file.
> > I could make a script that strips the escape characters in the log
> > file after execution, but I would prefer if the escape sequences were
> > never written in the file, so that no user intervention is needed.

>
> > I have an idea : we could pipe the output of toto to sed, but I don't
> > know if sed is able to print the input data both on the screen
> > (unaltered) and to a file (with escape chars removed)
> > Do you have a little trick that could solve my problem ?

>
> > Thanks to everyone and have a nice day !
> > Philippe

>
> toto | awk '{print;gsub(/[[:control:]]/,"")rint > "log";system("")}'
>
> system() flushes the buffer. In GNU awk you could use fflush().
>
> Ed.- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Hi, thanks for your quick answer ! However, the command does not work:

awk: syntax error near line 1
awk: illegal statement near line 1

Philippe

  Réponse avec citation
Vieux 06/11/2007, 16h26   #8
pmaire@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stripping ANSI escape characters from output

On 6 nov, 16:42, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 2007-11-06, pma...@gmail.com <pma...@gmail.com> wrote:
>
>
>
> > Hi
> > I have a program, let's call it 'toto', that generates text with color
> > (ansi escape codes)
> > I want to keep a log of toto's execution, and display its output with
> > the colors in real time, so at the moment, I do (in tcsh) :

>
> > toto |& tee execution.log

>
> > But when I read the log with nedit for example, the color codes
> > present in the log alter the readability of the file.
> > I could make a script that strips the escape characters in the log
> > file after execution, but I would prefer if the escape sequences were
> > never written in the file, so that no user intervention is needed.

>
> > I have an idea : we could pipe the output of toto to sed, but I don't
> > know if sed is able to print the input data both on the screen
> > (unaltered) and to a file (with escape chars removed)
> > Do you have a little trick that could solve my problem ?

>
> > Thanks to everyone and have a nice day !
> > Philippe

>
> toto |& tee /dev/tty | col -b > execution.log- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -


Hi, thanks for your answer.
col does not seem to work well : in my log file, I get
-----
34m1mInfo: test
0m35m1mWarning: tttiti
0m31m1mError: myerror
0mtest2
-----
However, the tee to /dev/tty is a good idea. I will try to use sed
instead of col in order to strip the escape sequences.
Regards
Philippe

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h34.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18462 seconds with 16 queries