removing terminal control characters

Discussion in 'Python' started by Aaron Kunkle, Sep 4, 2003.

  1. Aaron Kunkle

    Aaron Kunkle Guest

    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'\033[^;]*;')
    then passing each line of output through this:
    line = regex.sub("",line)
    junk = line.translate(identity, string.printable)
    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
     
    Aaron Kunkle, Sep 4, 2003
    #1
    1. Advertising

  2. Aaron Kunkle

    yaipa h. Guest

    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 <> wrote in message news:<>...
    > 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'\033[^;]*;')
    > then passing each line of output through this:
    > line = regex.sub("",line)
    > junk = line.translate(identity, string.printable)
    > 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
    >
    > --
     
    yaipa h., Sep 5, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris  Chiasson
    Replies:
    6
    Views:
    635
    Richard Tobin
    Nov 14, 2006
  2. gaurav kashyap
    Replies:
    3
    Views:
    6,690
    Paul Boddie
    Oct 31, 2008
  3. mix
    Replies:
    4
    Views:
    1,036
    Emile van Sebille
    Oct 30, 2010
  4. Steve
    Replies:
    2
    Views:
    955
    edicionsdigitals.com edicions digitals xarxa socia
    Dec 7, 2010
  5. Peter O'Reilly
    Replies:
    8
    Views:
    274
    LÄÊ»ie Techie
    Aug 7, 2004
Loading...

Share This Page