Re: replacing high order ascii chars using sed

From: Stephane CHAZELAS (stephane_chazelas@yahoo.fr)
Date: 04/15/03

  • Next message: Bill Marcum: "Re: replacing high order ascii chars using sed"
    From: Stephane CHAZELAS <stephane_chazelas@yahoo.fr>
    Date: 15 Apr 2003 09:44:01 GMT
    
    

    Josh Buedel wrote:
    > I'm trying to write a sed script that will replace certain control
    > characters and high order ascii chars with a printable character. I'm using
    > cygwin on a win2000 machine, from the windows command (cmd.exe) line.
    >
    > I have a couple of questions:
    >
    > 1. This command line
    > sed "s/[[:cntrl:]]/X/g" b2.bin
    > and this command line
    > sed "s/[\x00-\x19\x7F]/X/g" b2.bin
    > do not produce the same results. Why is this?
    >
    > 2. The byte size of the output was 12 bytes bigger than b2.bin's original
    > size of 851, for both expressions. Why is this? I'm replacing a single
    > character with a single character (I think).

    It seems to me that MS Windows has two types of file: binary and
    text, sed is a text utility, I don't know how it handles binary
    files, it may do some conversions (on NL or CR chars). I don't
    know wether CR is in cntrl on Windows or not.

    >
    > 3. What would the correct regular expression/command line be? I want to
    > replace all characters 0x7F and up with an 'X'.

    Use "tr" instead of sed (but pay attention to CR and NL chars).

    -- 
    Stéphane
    

  • Next message: Bill Marcum: "Re: replacing high order ascii chars using sed"

    Relevant Pages

    • Re: string substitution?
      ... character for the platform in question. ... Windows convention is, given that there isn't a single character for ... No single byte denotes end-of-line on Windows, ...
      (comp.lang.lisp)
    • Re: parse error before = token
      ... > us the previous character was the last one. ... the first 1024 bytes or so (in binary mode) and scan for control ... lots of null chars, control chars, or high bit set chars -> binary data ... Now I have left a nit for someone else to pick... ...
      (comp.lang.c)
    • Re: someone
      ... > I have to write a function that reads a number up to 20 chars long from the ... This loop reverses the order of the digits. ... Program: Request character from user. ... Return 2nd char in buffer. ...
      (alt.comp.lang.learn.c-cpp)
    • Re: Qt - appending single/multiple chars into QTextEdit
      ... Ideally the chars would be rendered in different ... Use fixed fonts for fast calculations and implement your own ... widget using QWidget and QScrollArea. ... to store the character and its source. ...
      (comp.programming)
    • Re: Sed question, please help
      ... "Michael Tosch" wrote in message ... So I'm assuming, using sed for the second example (assuming there's 21 fields, and field 21 is the last one and is 10 chars long, and field 20 starts at char 50 and ends at char 55)), I could also use ... you must further escape the curly brackets. ... I was aware that sed uses reg ex, but I thought the backslash was to escape the character after it, i.e. take that character literally, and as curly brackets are a special character, I thought that escaping them meant that sed would look for actual curly brackets in the file. ...
      (comp.unix.shell)