![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help on sed replacing special characters | prvnrk | Shell Programming and Scripting | 11 | 1 Week Ago 08:02 AM |
| Newbie: replacing strings containing special caracters | drumkid | UNIX for Dummies Questions & Answers | 1 | 04-03-2006 11:39 AM |
| replacing string with special character ??? | imppayel | Shell Programming and Scripting | 4 | 12-08-2004 01:07 AM |
| special characters | nawnaw | UNIX for Dummies Questions & Answers | 2 | 05-18-2004 12:17 PM |
| awk/sed with special characters | apalex | Shell Programming and Scripting | 5 | 05-06-2002 01:40 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Replacing French special characters
Hi,
I have tonnes of .txt files that are written in French. I need to replace the French special characters, however, with English equivalents (e.g. é -> e and ç -> c). I have tried this --- #!/bin/bash # Convert French characters to normal characters # Treat each of the files exec 3<&0 exec 0<frenchCharacters.txt while read currentFrenchCharacter do read currentReplacementCharacter sed -e "s/$currentFrenchCharacter/$currentReplacementCharacter/g" $1 > $1.frenchCharactersReplaced mv $1.frenchCharactersReplaced $1 done # Close the file exec 3<&0 --- where "frenchCharacters.txt" contains a list of characters, where the first is the character to find and the second is the character to replace it with. The problem is that it doesn't make any changes to the file that I send in (stored in $1). Anyone know why? Also, anyone know of a better way to do this? |
| Forum Sponsor | ||
|
|
|
|||
|
No magic tool. Just sed:
Code:
sed 's/[àâä]/a/g; s/[ÀÂÄ]/A/g; s/[éèêë]/e/g; s/[ÉÈÊË]/E/g; s/[îï]/i/g; s/[ÎÏ]/I/g; s/[ôö]/o/g; s/[ÖÔ]/O/g; s/[ûüù]/u/g; s/[ÛÜÙ]/U/g; s/ç/c/g; s/Ç/C/g' your file Code:
sed -i 'sed command' your_file |
|
|||
|
Well, yes. And it's even more elegant:
Code:
SPEC_CHAR="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ" NORM_CHAR="AAAAAAACEEEEIIIIDNOOOOOOUUUUYPSaaaaaaaceeeeiiiionoooooouuuuyby" sed -i.bk 'y/'$SPEC_CHAR'/'$NORM_CHAR'/' file-to-process |
|||
| Google The UNIX and Linux Forums |