A Script To Easily Search Simplified Chinese Words With CC-CEDICT In Linux

Last Updated on February 15, 2017

This article is a follow up to my article called A Script To Easily Search Traditional Chinese Words With CC-CEDICT In Linux here. This article is about how to search the CC-CEDICT Chinese-English dictionary using Simplified Characters in Linux.

1. Bash Shell Script For Searching Simplified Chinese Words With CC-CEDICT

Below is the raw code for the script. If you would prefer to download the whole script as a file, you can download it here.

#this script reads in Simplified Chinese input and assigns it to a variable called chinese_words
#then grep searches the content and outputs the definition
#This script only words with Simplified Chinese Characters / Words
echo "Enter the Simplified Chinese Character or Word that you want to search:"
read chinese_words
othercontent=$(for ((w=1;w<=$length;w++)); do echo -n "."; done)
grep "^$(echo $othercontent) $chinese_words " current_cc-cedict.txt

Next you need to actually download the CC-CEDICT file. You can download a version of the dictionary here. Download the text file version and extract the zip file.

Currently, the CC-CEDICT file I have is called cc-cedict_2017_01_08.txt
Rename the file as current_cc-cedict.txt
By command line you can rename it by doing:
mv cc-cedict_2017_01_08.txt current_cc-cedict.txt
Or you could just rename it manually using your GUI.

Download both those files into a folder, then cd into that folder, and then to run the script do:
bash search_simplified_chinese.sh

For this article, I am going to assume you downloaded the script and dictionary file into a folder called cc-cedict inside the ~/Downloads folder. Specifically they will be downloaded in ~/Downloads/cc-cedict/

How To Use The Script

Here is an example of how to use the script. Open a terminal and type:

cd ~/Downloads/cc-cedict/
bash search_simplified_chinese.sh
Enter the Simplified Chinese Character or Word that you want to search:

It will then output:
我們 我们 [wo3 men5] /we/us/ourselves/our/

that is all ☺

If you are interested in learning about bash scripting, you can read about it here.

2. Create A Bash Alias For Conveniently Searching The CC-CEDICT With Simplified Characters Many Times

If you use the script for searching Simplified Chinese Characters often, as I do, you can create an alias in bash, to make the command super easy to use over and over again without having to cd into the folder where the script is and run bash start_chinese.sh every time.

For this alias, we will assume the script search_simplified_chinese.sh and the CC-CEDICT file called current_cc-cedict.txt are in ~/Downloads/cc-cedict/

There are 2 ways to set up the bash_aliases file
You can download my alias file, or you can manually set up your bash_aliases file yourself using a text editor.

Way 1: Set Up The Alias By Downloading Alias File

Download my alias file here into your home folder.

Then rename the file bash_aliases_a.txt as .bash_aliases
by typing:
mv bash_aliases_a.txt .bash_aliases

Way 2: Set Up The Alias Manually With A Text Editor

Now for setting up the bash alias. Do the following commands:
cd ~
Next use your favorite text editor, and create a file called .bash_aliases
my favorite text editor is vim, so in this example, I use vim as the text editor.
vim .bash_aliases
now inside the file copy the following line
alias zhongguosimplified='aaa=$(pwd) && cd ~/Downloads/cc-cedict/ && bash search_simplified_chinese.sh && cd $aaa'
(If your .bash_aliases file already has lines in it, just add the above line below them.)
And finally save the file.

Testing the Alias

Now, close all your terminals. And reopen a terminal. Now if you type in zhongguosimplified in any terminal, it will then prompt you to input the Simplified Chinese Characters, and once you do, it will then output the definition.

Enter the Simplified Chinese Character or Word that you want to search:
電腦 电脑 [dian4 nao3] /computer/CL:臺|台[tai2]/

I called this alias zhongguosimplified. But you can call it anything you want. Adjust the name in the bash_aliases file if you want.

What did you think of this article? Do you like the script and alias? Let’s discuss it in the comments below.

Leave a comment

Your email address will not be published. Required fields are marked *