2.14 Spell check and dictionary operation

Source: Internet
Author: User

Most Linux distributions contain a dictionary file, along with a aspell tool that is useful for spell checking

1, the directory/usr/share/dict/contains some dictionary files, "dictionary file" is a dictionary word list contains a text file, you can use this list to check whether a word is a word in the dictionary.

To check whether a given word belongs to a word in the dictionary, use the following script:

#!/bin/bash

#文件名: checkword.sh

Word=$1

grep "^$1$"/usr/share/dict/british-english-q

If [$?-eq 0]; Then

Echo $word is a dictionary word;

Else

Echo $word is not a dictionary word;

Fi

The syntax for this script is as follows:

./checkword.sh ful

Ful is not a dictionary word

./checkword.sh Feel

Ful is a dictionary word

Working principle

In grep, ^ marks the beginning of a word, and $ marks the end of the word.

-Q Disables the generation of any output

We can also use the spell checker command Aspell to check a word in the dictionary

#!/bin/bash

#文件名: aspellcheck.sh

Word=$1

Output= ' echo \ ' $word \ ' | Aspell List '

If [-Z $output];then

Echo $word is a dictionary word;

Else

Echo $word is not a dictionary word;

Fi

When the given input is not a dictionary word, the Aspell List command produces the output text, and conversely does not produce any output,-Z is used to confirm whether the $output is empty.

Lists all the words in the file that start with a specific word:

$look Word filepath

Or

$grep "^word" filepath

By default, if the file parameter is not given, the look command uses the default dictionary (/usr/share/dict/words) and returns the output.

$look Word

#像这样使用时, the Look command takes the default dictionary as the file parameter

2.14 Spell check and dictionary operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.