#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    147
    Rep Power
    15

    Question replace non-ascii characters


    Hi,

    I'm trying to replace "smart quotes" in a files with regular ascii quotes.

    This command worked for me:
    tr '\222' \' < infile > outfile

    (222 is octal for the right single quote)

    But then I realized that I have to replace the quote with backslash-quote. The tr command only works to replace one character. And the sed command doesn't seem to work with \222.
    Any suggestions?

    I had the idea to use the tr command to convert the smart-quote to another character, and then use the sed command to replace that character with \' but there is no character on the keyboard that isn't already being used in the file.

    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    14
    Try this:

    echo 'abc \222 def' | sed 's=\\222='\''=g'

    Every quote in the sed expression is a single quote. There are two quoted strings: 's=\\222=' and '=g'. Between the quoted strings is \' which is a backslashed quote. The shell puts these all together and feeds it into sed.

IMN logo majestic logo threadwatch logo seochat tools logo