InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
Bash
Removing Smart Quotes in bash
Bash

Removing Smart Quotes in bash

InfinityCoder February 19, 2017

You want simple ASCII text out of a document in MS Word, but when you save it as text some odd characters still remain.

Translate the odd characters back to simple ASCII like this:

1
$ tr '\221\222\223\224\226\227' '\047\047""--' <odd.txt >plain.txt

Such “smart quotes” come from the Windows-1252 character set, and may also show up in email messages that you save as text.

To quote from Wikipedia on this subject:       A few mail clients send curved quotes using the Windows-1252 codes but mark the text as ISO-8859-1 causing problems for decoders that do not make the dubious assumption that C1 control codes in ISO-8859-1 text were meant to be Windows-1252 printable characters.

To clean up such text, we can use the tr command. The 221 and 222 (octal) curved single-quotes will be translated to simple single quotes.

We specify them in octal (047) to make it easier on us, since the shell uses single quotes as a delimiter.

The 223 and 224 (octal) are opening and closing curved quotes, and will be translated to simple
double quotes.

The double quotes can be typed within the second argument since the single quotes protect them from shell interpretation.

The 226 and 227 (octal) are dash characters and will be translated to hyphens (and no, that second
hyphen in the second argument is not technically needed, since tr will repeat the last character to match the length of the first argument, but it’s better to be specific).

 

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Sending Email from Your Script in bash
You’d like your script to be able to send email, …

Sending Email from Your Script in bash

Avoiding Common Security Problems in bash
You want to avoid common security problems in your scripting. …

Avoiding Common Security Problems in bash

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap