I have a file that fetches descriptions from the DB. The values have special characters in them. So while writing the same into the file after converting to DOS the characters change to something else.
So as a correction i have used sed command to replace the converted characters to the original special character and it works. I could do for all the special characters that were present in DB.
Examples :
Original : CANDELE 50°
After conversion to dos its visible as CANDELE 50Áø .So i used a sed command sed -e 's/Áø/°/g'
What i want to do now is a permanent fix to automatically change any special character that comes in. is there any command that automatically converts a special character to its original after conversion to dos so that I can avoid a manual addition for every character.
Kindly help me doing the same:
 changeFileFormat () {
    cd $1
    echo "Changing file format Unix -> DOS." >> $LOG_FILE
    for file in `ls *.csv`
    do  
        mv ${file} ${file}_unix
        unix2dos ${file}_unix >> ${file}_dos
        sed -e 's/ÁøU/°/g' -e 's/Âû/Ó/g' -e 's/‹¨«//g'  -e 's/ª/ì/g' -e 's/¸/ù/g' -e 's/Áœ/£/g' -e 's/Á¨/¿/g' -e 's/ƒâª/€/g' ${file}_dos >> ${file}
        if [ $? -ne 0 ]; then
            echo "Conversion failed for file: [ $file ]." >> $LOG_FILE
            mv ${file}_unix ${file}
        else
            rm -f ${file}_dos
            rm -f ${file}_unix
        fi;
    done
    echo "Conversion finished." >> $LOG_FILE
}
- DB description : CANDELE 50°
- CSV file that gets created in unix : ART|M|02A_1057M5706 |CANDELE 50°
- After DOS conversion : ART|M|02A_1057M5706 |CANDELE 50Áø
- After SED command : ART|M|02A_1057M5706 |CANDELE 50°
