0

When we are trying to redirect an output from an production server to local system, there are some unwanted characters eg. ^[[032m. actually these are the color codes which is appearing while its redirected. When the same script is executed on the server without redirection some part of the output appears in colored format.

If we open this file directly in the notepad or any other tool it shows come different character like below.

enter image description here

So is there any possible solution to skip them to happen before or after redirection.

  • 1
    What program generates these codes? What does the manual for that program say about not generating them? – thrig Nov 15 '17 at 16:10
  • Try setting TERM to some value for terminal that doesn't have these codes, e.g. export TERM=dumb, before starting the program that produces this output on the production server. If the escape sequences are not hardcoded, that might prevent producing them. – dirkt Nov 15 '17 at 16:28
  • @dirkt, or just TERM=dumb somecommand > outputfile so that the setting doesn't stay active for later commands in the shell. – ilkkachu Nov 15 '17 at 16:31
2

If you have GNU sed, you can use that to remove the color escapes from the stream:

somecmd |sed -Ee 's/\x1b\[[0-9;]+m//g'  > outputfile

The sed command substitutes (s///) the escape character (\x1b), followed by an open bracket (\[), and any number of digits or semicolons ([0-9;]+) and a following m, with nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.