Skip to content

Instantly share code, notes, and snippets.

@kamermans
Last active April 16, 2024 00:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kamermans/1f871268f51d21e9930c004493eba76d to your computer and use it in GitHub Desktop.
Save kamermans/1f871268f51d21e9930c004493eba76d to your computer and use it in GitHub Desktop.
Replace fancy-quotes / curly-quotes / smart-quotes with standard ASCII single- and double-quotes in bash
#!/bin/bash
# Replaces annoying "fancy" quotes created by programs like Microsoft Word and everything in MacOS
# with normal ASCII single-quotes (') or double-quotes (")
# This script does NOT replace the GRAVE ACCENT (`) since it is commonly used in Markdown and as a bash command
# See: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
SINGLE=$(echo -ne '\u00B4\u2018\u2019')
DOUBLE=$(echo -ne '\u201C\u201D')
sed -i "s/[$SINGLE]/'/g; s/[$DOUBLE]/\"/g" $1
@johnmckerrell
Copy link

There's a typo in the script, first line should be:

#!/bin/bash

(i.e. a hash, not a dollar)

Also, for the record, Mac users will need to specify an extension for the backup file if using -i so the last line needs to be, e.g.:

sed -i".bk" "s/[$SINGLE]/'/g; s/[$DOUBLE]/\"/g" $1

@kamermans
Copy link
Author

Thanks @johnmckerrell, I must have typoed it when I made the gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment