Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Shell script for following conditions. Take two files as input and run spell command on it, Collect a list of potential spelling errors, modify file

Posted By: Mason Evans     Category: Unix / Linux / Ubuntu     Views: 3440

Write a shell script according to following conditions.
1) Take two files as input and run spell command on it.
2) Collect a list of potential spelling errors.
3) Show the user each word from the list, letting the user to enter the correction for that word or accept that word as it is.
4) Finally modify the original files with corrected spellings.

Code for Shell script for following conditions. Take two files as input and run spell command on it, Collect a list of potential spelling errors, modify file in Unix / Linux / Ubuntu

clear 
echo -e "enter file one : \c"
read fone

while [ -z "$fone" ] ;
do
echo -e "request :: please enter file name "
    echo -e "\n\tfile one : \c"
    read fone
done

if [ ! -e $fone ] ; then
    echo -e "error :: file one $fone doesn't exist. can't proceed."
    read empty
    exit 1
fi

echo -e "enter file two : \c"
read ftwo

while [ -z "$ftwo" ];
do
echo -e "request :: please enter file name "

    echo -e "\n\tfile two : \c"
    read ftwo
done

if [ ! -e $ftwo ] ; then
    echo -e " error :: file one $ftwo doesn't exist. can't proceed."
    read empty
    exit 1
fi

spell $fone $ftwo > spellerror.log
errword=`cat spellerror.log | wc -l`
echo -e "enter for continue"

echo -e "wrong spelling in both fiels : " 
cat spellerror.log
echo -e "total wrong words = $errword "
echo -e "\n enter for continue"
read empty

while [ $errword -gt 0 ] ;
do
    word=`sed -n "$errword p" spellerror.log `
    echo -e "word -> $word "

    echo -e "do u want update? (y/n) : \c "
    read choice

    if [ $choice = "y" -o $choice = "y" ]; then
        echo -e "new word : \c"
        read newword
    
        findfile=`grep -e $word -c $fone`
        if [ $findfile -gt 0 ]; then
        sed "s/$word/$newword/g" $fone > fone.tmp
            mv -f fone.tmp $fone
        fi
    
        findfile=`grep -e $word -c $ftwo`
        if [ $findfile -gt 0 ]; then
        sed "s/$word/$newword/g" $ftwo > ftwo.tmp
            mv -f ftwo.tmp $ftwo
        fi
    fi
    
    errword=`expr $errword - 1`

done    
 
OUTPUT
***********
[04mca58@LINTEL 04mca58]$ sh spell1.sh

enter  file one : 
f1

enter  file two : 
f2                           

enter forcontinue

                 wrong spelling:- 
ths
fle
chk
purps

 enter forcontinue                                                  

wrong word -> ths
do u want to update? (y/n) : y
new word : this

wrong word -> fle
do u want to update? (y/n) : y
new word : file

wrong word ->chk
do u want to update? (y/n) : y
new word : check

wrong word -> purps
do u want to update? (y/n) : y
new word : purpose
  
Share: 



Mason Evans
Mason Evans author of Shell script for following conditions. Take two files as input and run spell command on it, Collect a list of potential spelling errors, modify file is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!