문제

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!

도움이 되었습니까?

해결책 3

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

다른 팁

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.

i use a pipe or direct sed like this

sed 's/[^[:print:]]\[[^a-zA-Z]*[a-zA-Z]//g' YourFile
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top