LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-27-2008, 04:05 AM   #1
bala.linux
LQ Newbie
 
Registered: Feb 2008
Distribution: Ubuntu, Centos
Posts: 10

Rep: Reputation: 0
Thumbs up 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
 
Old 03-27-2008, 06:49 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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
 
Old 03-27-2008, 11:51 AM   #3
bala.linux
LQ Newbie
 
Registered: Feb 2008
Distribution: Ubuntu, Centos
Posts: 10

Original Poster
Rep: Reputation: 0
Exclamation

Quote:
Originally Posted by pixellany View Post
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
Thanks for your reply.
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?
 
Old 03-27-2008, 01:28 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OOXML's (Out of) Control Characters LXer Syndicated Linux News 0 03-25-2008 04:50 PM
[SOLVED] control characters in vi procfs Linux - Newbie 4 08-30-2007 10:52 PM
Viewing control characters in a text file dmorse Linux - General 2 01-06-2007 11:10 PM
Clearing control characters from a text file LinuxLala Linux - General 1 04-07-2006 06:45 AM
wxPython: control handling its own events? Hko Programming 1 07-30-2005 06:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration