**A Find/Replace Bash Script for Unicode Symbols** [home](..) _posted 2015-11-20_ As part of my day job, I enter recipe content into a custom-made CMS that does not support special characters, which means that ingredient quantities encoded as, for example, ½, do not render correctly. As it happens, editors typically send me a Word doc with all manner of special characters like fractions, ° instead of "degrees," and smart quotes. For years I have been using Find/Replace in my text editor, but after completing the [Command Line tutorial at Codecamy](https://www.codecademy.com/learn/learn-the-command-line) it occurred to me that a bash script would save me time. The following script performs a global find/replace on a hodge-podge of the characters that I regularly encounter. I also use this script to expand some time abbreviations (min., hr.). My company's IT department does not allow me to save bash scripts to a /bin/ directory, so I just save it in a /scripts/ directory. I call this script `rr`. I made it executable by typing `chmod +x rr`. Then if I want to run it from another directory, I type `~/j/scripts/rr filename.txt` (where filename.txt is a text file into which I have pasted the contents of a Word doc that I copied to the system clipboard). The `-i -e` commands allow sed to perform a find/replace in the file and overwrite it. Any backslashes are used to escape special characters. I am not well-versed in regular expressions, so if there is a more efficient way to perform the following, please let me know in the comments. ~~~~~~~~~~~~~~~~~~ #! /bin/bash file=$1 sed -i -e 's/¼/1\/4/g' $file sed -i -e 's/½/1\/2/g' $file sed -i -e 's/°/ degrees/g' $file sed -i -e 's/¾/3\/4/g' $file sed -i -e 's/min\./minutes/g' $file sed -i -e 's/hr\./hours/g' $file sed -i -e 's/⅓/1\/3/g' $file sed -i -e 's/“/\"/g' $file sed -i -e 's/”/\"/g' $file ~~~~~~~~~~~~~~~~~~~ **Related posts:** * [Command Line Script to Make Your iPhone Dial a Number](http://blog.jeffreykishner.com/2014/07/24/commandLineScriptToMakeYourIphoneDialANumber) * [Send Text and an Action to Drafts for iOS From the Command Line](http://blog.jeffreykishner.com/2014/05/23/sendTextAndAnActionToDraftsForIosFromTheCommandLine.html) * [Command Line Script for "Paperless: Lists + Checklists"](http://blog.jeffreykishner.com/2014/07/07/commandLineScriptForPaperlessListsChecklists.html)