4

I got a log from remote linux computer. It looks like:

2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0  
2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55^M  
2013-10-23T08:19:07+0300 ^[[?1034h-bash-4.1$ date  
2013-10-23T08:19:07+0300 Wed Oct 23 08:19:07 EEST 2013  
2013-10-23T08:19:08+0300 -bash-4.1$ ls  
2013-10-23T08:19:08+0300 ^[[0m^[[01;34m99^[[0m #avail.info ^[[01;34mgmoTemp^[[0m raml21.dtd SNMP4JTestAgentBC.cfg  
2013-10-23T08:19:08+0300 an_mainHost_localhost_20131023081654000136.xml #avail.info~ gsh.txt ^[[01;34mresults^[[0m  
2013-10-23T08:19:09+0300 ^[[m-bash-4.1$ exit  
2013-10-23T08:19:09+0300 logout

But it should be:

Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0  
Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55  
-bash-4.1$ date  
Wed Oct 23 08:19:07 EEST 2013  
-bash-4.1$ ls  
99                                              #avail.info   gmoTemp  raml21.dtd  SNMP4JTestAgentBC.cfg  
an_mainHost_localhost_20131023081654000136.xml  #avail.info~  gsh.txt  results  
-bash-4.1$ exit  
logout  

The messy codes are terminal control escape sequences, you can use command "infocmp xterm" and "man terminfo" to get more details.
My question is how can I remove these terminal control escape sequences in the file?
Thanks a lot!

Jeff7566
  • 432
  • 1
  • 5
  • 20
  • Neither answer suffices for the example. See [Can I programmatically “burn in” ANSI control codes to a file using unix utils?](http://stackoverflow.com/questions/28269278/can-i-programmatically-burn-in-ansi-control-codes-to-a-file-using-unix-utils/28334291#28334291). – Thomas Dickey Oct 04 '16 at 09:05

3 Answers3

4

Simple way to remove most parts of the control character is using the command below in vim:

:%s/<escape-key>\[[0-9;]*m/ /g

Press Ctrl+V followed by esc-key for the <escape-key> character above. Everything else is the same literal key as in your keyboard.

vahid abdi
  • 9,636
  • 4
  • 29
  • 35
guest
  • 41
  • 3
4

i use a pipe or direct sed like this

sed 's/[^[:print:]]\[[^a-zA-Z]*[a-zA-Z]//g' YourFile
NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
0

I solved this issue using lots of regular expressions according to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Dag Høidahl
  • 7,873
  • 8
  • 53
  • 66
Jeff7566
  • 432
  • 1
  • 5
  • 20