How to convert special characters?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert special characters?
# 1  
Old 09-16-2013
How to convert special characters?

Hi All,

I have some text including Turkish characters and the 3rd party application that reads my file does not supporting this character set (at least, I have no control on it).

So, I used below conversion for maximum character support but still have problems with "İ" and "Ş". Application displays those characters as "Ý" and "Ð".

Code:
iconv -f utf8 -t iso8859_9  file1 > file2

Solution is to convert all İ->I and all Ş->S at source text. But I have no idea how to find those special characters.

Something like that is not working:
Code:
:%s/İ/I/g

Thanks for helping.

Last edited by Scott; 09-16-2013 at 05:30 PM.. Reason: Code tags
# 2  
Old 09-16-2013
Hi,
Here an example how to proceed with sed command (gnu):
file input:
Code:
$ cat xx.trc
So ist denn alles, was ihr Sünde,
Zerstörung, kurz das Böse nennt,
Mein eigentliches Element.

Octal code special character
Code:
$ sed -n 'l' xx.trc
So ist denn alles, was ihr S\303\274nde,$
Zerst\303\266rung, kurz das B\303\266se nennt,$
Mein eigentliches Element.$

Replace special character (here ö by o and ü by u):
Code:
$ sed 's/'$(echo -e "\0303\0274")'/u/g;s/'$(echo -e "\0303\0266")'/o/g' xx.trc
So ist denn alles, was ihr Sunde,
Zerstorung, kurz das Bose nennt,
Mein eigentliches Element.

Regards.
This User Gave Thanks to disedorgue For This Post:
# 3  
Old 09-17-2013
Hi

Thank you for the answer.
What is the purpose behind "sed -n 'l' xx.trc" command?
# 4  
Old 09-17-2013
Did you try:
Code:
tr İŞ IS < file

or
Code:
sed y/İŞ/IS/ file

# 5  
Old 09-17-2013
Command l of sed is for:
List out the current line in a ``visually unambiguous'' form.
As like "od -c" but visually more readable.

Regards.
# 6  
Old 09-25-2013
Thanks for all answers.
Special thanks to disedorgue that he helped me a lot and I solved my problem by converting octal matches of special characters.

Here is the needed lines :

Code:
sed 's/'$(printf "%b\n" "\0336")'/S/g' test Ş->S
sed 's/'$(printf "%b\n" "\0335")'/I/g' test İ->I
sed 's/'$(printf "%b\n" "\0320")'/G/g' tes Ğ->G


Last edited by radoulov; 09-25-2013 at 08:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove special characters?

Hi Gurus, I have file which contains some unicode charachator like "ü". I want to replace it with some charactors. I searched in internet and got command sed "s/ü/-/g", but I don't know how to type ü in unix command line. Please help me for this one. Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

2. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

3. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

4. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

5. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

6. Shell Programming and Scripting

Convert special charachter ^C to new line

Hi, I have a file, which contains ^C or ^A characters from mainfrme system, it's dec 192 or octal 300 hex C0. I want to replace this character with new line. I used commands, but it didn't worked. tr '\o300' '\n' <t >t2 #or tr '\xC0' '\n' <t > t2 Can somebody help me to do... (2 Replies)
Discussion started by: vnag97
2 Replies

7. UNIX for Dummies Questions & Answers

Substitue 'Special Characters' in VI

Hi All, I am using LATEX and need to delete all the lines in a file matching: \begin{work} I know there are several ways to do this, but I am trying to do it with the substitute command in VI. The problem is I can't get substitute to recognize the character '\'! How do I do it? ... (7 Replies)
Discussion started by: ScKaSx
7 Replies

8. Shell Programming and Scripting

sed with special characters

Hi, I am reading a file (GC_JAR.log) which has entries like: 511725.629, 0.1122672 secs] 525268.975, 0.1240036 secs] 527181.835, 0.2068215 secs] 527914.287, 0.2884801 secs] 528457.134, 0.2548725 secs] I want to replace all the entries of "secs]" with just "secs" Thus, the output... (4 Replies)
Discussion started by: itzz.me
4 Replies

9. Shell Programming and Scripting

convert special character like £

i had a shell script writing a xml file. I need to use "& # 163;" instead of "£", and replace others characters like: > to &gt; , and so on.. Anyone know how to convert the character automatically? my script as below: do # GET FEED REC SQL2="SELECT A.*, B.subject FROM feed_details A,... (1 Reply)
Discussion started by: cynnie
1 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question