Handling Control Characters in Linux.
Hello All,
I have a doubt in processing the control characters in unix. Assume that I have logged all the user's key press with output in a text file which has terminal control characters. For example, ^[]0;root@2FWD49:~^G[root@2FWD49 ~]# l^H^[[Kdate^M Thu Mar 27 14:40:54 IST 2008^M ^[]0;root@2FWD49:~^G[root@2FWD49 ~]# clear^M ^[[H^[[2J^[]0;root@2FWD49:~^G[root@2FWD49 ~]# logout^M ^[[H^[[2J I want to process all the control characters and get the content like below, [root@2FWD49 ~]# date Thu Mar 27 14:40:54 IST 2008 [root@2FWD49 ~]# clear When I cat that file, I get the above output (terminal process the characters and shows). I am looking a unix utility to perform. Please let me know in case any command in unix does this job. Thanks and Regards, Bala |
There are lots of tools to do something like this. I would start with SED.
The trick is to define the generic pattern you want to remove. I'm having trouble defining the pattern in any simple way. Here is one example to get started: sed 's/\^.*;//g' filename This deletes all strings beginning with "^" and ending with ";" Go here for a really good tutorial on SED: http://www.grymoire.com/Unix/Sed.html |
Quote:
I just donot want to replace the control character. If I want, then I can just use 'sed'/'tr'. But I need to process them. Like, clead(backspace)r I want the output to be clear and not cleadr. Is this possible? |
Using this example--but the way you stated it in the original post.
Before: clear^M After: clear sed 's /\^.//g' filename > newfilename This deletes all occurrences of "^" followed by any single character. The problem is that the constructs you want to delete are more complicated. |
All times are GMT -5. The time now is 10:23 AM. |