473,796 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing terminal control characters

i'm trying to display output from a linux command line program and i'm
getting a lot of junk.
i was told that pulling out escape sequences like this regex: \033[^;]*;
would do it but that doesnt catch them all. i'm seeing the little box
characters for instance.

the only way i've found thus far is this:

building the regex object:
regex = re.compile(r'\0 33[^;]*;')
then passing each line of output through this:
line = regex.sub("",li ne)
junk = line.translate( identity, string.printabl e)
line = line.translate( identity, junk)

i know there must be a better way!
is there a way to get a non-printable group of characters to search
for?

thanks,
aaron kunkle

Jul 18 '05 #1
1 3204
Aaron,

Have a look at "Text Processing in Python," by David Mertz.
Wonderful book, just bought it from Amazon.com

Here is a link to the soft copy.
http://gnosis.cx/TPiP/

Cheers,

--Alan

Aaron Kunkle <aa***@brokenso ciety.com> wrote in message news:<ma******* *************** ************@py thon.org>...
i'm trying to display output from a linux command line program and i'm
getting a lot of junk.
i was told that pulling out escape sequences like this regex: \033[^;]*;
would do it but that doesnt catch them all. i'm seeing the little box
characters for instance.

the only way i've found thus far is this:

building the regex object:
regex = re.compile(r'\0 33[^;]*;')
then passing each line of output through this:
line = regex.sub("",li ne)
junk = line.translate( identity, string.printabl e)
line = line.translate( identity, junk)

i know there must be a better way!
is there a way to get a non-printable group of characters to search
for?

thanks,
aaron kunkle

--

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1437
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display. From doing weird alignment things, to making it so that so long as those characters are visible, the display is always scrolled to a line where one of those screwy ASCII characters are. I can scroll up or down, but as soon as I type something on...
3
5580
by: Josh Schmidt | last post by:
How can one set the terminal services profile and home directory path in AD using VB.NET? I can set the usual profile paths, but terminal services properties are not supported with ADSI. Any help is greatly appreciated! Josh
8
14275
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have filled out in the prior page's form elements. Naturally some users like to copy and paste text into the textarea box and presumably do so from say a word processor program. Some Macintosh based users I know of experience problems with foreign...
1
2146
by: Adriaan Renting | last post by:
I have the problem that I need to interact with a CD/DVD burning program called gear. I do this by running it in a pseudo terminal. I also need to log what I'm doing, so I copy all output I get from gear to a logfile. The problem is that gear uses terminal control commands to create a nice commandline interface. I can filter out all non printable characters to get something I can put in my logfile, but this leaves a lot of the terminal...
2
2312
by: Jacob Kjaergaard | last post by:
Hi! Im looking for a (relatively) easy way to print at the same spot on the terminal. Like i.e wget does when showing the progressbar and the percentage of the download. if been looking in the source code to wget, but it seems very comprehensive. printf normally "scrolls" this is what I want to control.
6
2940
by: Terry Olsen | last post by:
I need to make a terminal window to emulate special characters of a vintage PC. I don't think I can use a console because you can't change its font...can you? So what is the best way to make a terminal window that has a scrollback and is easy to position the cursor? How does hyperterminal & SmartTerm do it? Thanks!
7
2427
by: Captain Dondo | last post by:
I'm working on a terminal emulator for an embedded system. The key requirements are small size, code clarity, maintainability, and portability. We have machines that regularly see a service life of 30 years so it's not impossible that this code will be around that long. I'm trying to use termcap info to map incoming strings to display actions. In other words, I have an array that holds termcap info:
13
4611
by: sayansayan | last post by:
two threads are running in a prog i need the output of one thread in a new terminal which the prog will create and the output of other thread in the old terminal
2
1604
by: David | last post by:
Hi list. I've never used unicode in a Python script before, but I need to now. I'm not sure where to start. I'm hoping that a kind soul can help me out here. My current (almost non-existant) knowledge of unicode: string types. What I don't understand yet is what encodings are and when you'd want/need to use them. What I'd like is to just be able to
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.