Converting Unicode file to UTF8 format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting Unicode file to UTF8 format
# 1  
Old 07-31-2009
Converting Unicode file to UTF8 format

Hi,

I have a file in my desktop which is a unicode format. After this file is transferred to Unix using FTP, we are seeing some special character (like rectangle box type) at the first line. The same file is saved as UTF8 (using textpad tool, selecting encode to UTF-8 option) on my desktopand and then FTP to Unix. We could see proper data content.

I tried using the following command in Unix server (We use IBM AIX), but i got error message "Converter can not open"
iconv -f <iso89> -t <utf8> oldfile > newfile

Could you please let us know how we can automatically convert the file to UTF-8 in Unix server itself.

Thanks in advance for any help.

Thanks,
Venkat
# 2  
Old 07-31-2009
See this
[URL="https://www.unix.com/aix/18810-dos2unix-equivalent-aix.html"]

may try this
create a one line script 'd2u' using vi as
Code:
sed -i "s/^M//g" $1

(^M - Ctrl+v Ctrl+m)
# 3  
Old 07-31-2009
Hi,

Thanks for the reply. I have already handled replacing ^M characters in shell script. The issue with other special character (like rectangle shaped one). This character will be in the first position only in first line.

I will tell what i am doing. We get csv file from SAP server in our Unix server. This file has delimitter of tab. We need to replace tab with comma.
We have script that replaces tab with comma.

Before changing tab to comma, we opened the file from telnet and found the rectangle box in the first position in the first line.

After changing tab to comma using shell script, we opened the file from telnet and we noticed rectangle box in the first position in the first line.

When we download this file to our windows box and opened in excel by double clicking. We are seeing small small boxes and no content. If we open in notepad then we are able to see the content.

We manually removed rectangle shaped content from Unix and download into windows and opened the file in excel. This time, we are able to see the content.

We searched in google to get some help. They are telling it is something to do with encoding to UTF-8 before FTPing to Unix server. We have this capability in notepad, but we wanted to do this program without user intervention.

Please help me.

Thanks in advance.
Venkat
# 4  
Old 07-31-2009
What is the output of
Code:
iconv -l

# 5  
Old 08-03-2009
Hi fpmurphy,

I got the following

$iconv -l
ASCII-GR
CNS11643.1986-1
CNS11643.1986-2
GB18030
GBK
IBM-1046
IBM-1124
IBM-1129
IBM-1251
IBM-1252
IBM-1390
IBM-1394
IBM-1399
IBM-850
IBM-856
IBM-921
IBM-922
IBM-932
IBM-943
IBM-eucCN
IBM-eucJP
IBM-eucKR
IBM-eucTW
IBM-sbdTW
IBM-udcJP
IBM-udcTW
ISCII.1991
ISO8859-1
ISO8859-1-GL
ISO8859-1-GR
ISO8859-15
ISO8859-15-GL
ISO8859-15-GR
ISO8859-2
ISO8859-2-GL
ISO8859-2-GR
ISO8859-3
ISO8859-3-GL
ISO8859-3-GR
ISO8859-4
ISO8859-4-GL
ISO8859-4-GR
ISO8859-5
ISO8859-5-GL
ISO8859-5-GR
ISO8859-6
ISO8859-6-GL
ISO8859-6-GR
ISO8859-7
ISO8859-7-GL
ISO8859-7-GR
ISO8859-8
ISO8859-8-GL
ISO8859-8-GR
ISO8859-9
ISO8859-9-GL
ISO8859-9-GR
JISX0201.1976-0
JISX0208.1983-0
KSC5601.1987-0
TIS-620
UCS-2
UNICODE-2
UTF-16
UTF-16le
UTF-32
UTF-8
big5
ct
fold7
fold8
uucode
$

Thanks.
Venkat
This User Gave Thanks to vfrg For This Post:
# 6  
Old 08-04-2009
Hi,

I was able to successfully convert the file to UTF-8 format using the following command

iconv -f ISO8859-9 -t UTF-8 <input_file> > <output_file>

I still have one issue. We will receive file with encode type format ANSI and in some cases UTF-8.

If the file comes with encode type to ANSI, then using above command, we change the file to UTF-8. This is not an issue.

But if the file is comes with UTF-8 and if we run above command then the file special characters are not coming properly.

We need to run iconv command only if the file encode type is ANSI. If it is UTF-8 then we should not run iconv. How do we identify the encode of file in UNIX. Please help me in finding this.

Thanks.
Venkat
# 7  
Old 08-25-2009
Quote:
Originally Posted by vfrg
We need to run iconv command only if the file encode type is ANSI. If it is UTF-8 then we should not run iconv. How do we identify the encode of file in UNIX. Please help me in finding this.
Code:
file <input file>

should do it.
This User Gave Thanks to CRGreathouse For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help required in converting a file format

My file format: -------------------------------------------------- Complete Consistency Check Valid Area : VALID:VALID Started by : esanwad Started at : Thu Dec 11 16:04:46 2014 CNA version : R21H04_EC08 Check range : AREA VALID/VALID ... (4 Replies)
Discussion started by: Gautam Banerjee
4 Replies

2. Shell Programming and Scripting

Need help in converting the file format

Hi All, I need help in converting the mentioned file format into desired output format using awk. Could anyone help me in this? Below is the input.. Date Account Campaign AdGroup Keyword Conversion Revenue Var1 Var2 Var3 Var4 Var5 10 20 30 ... (8 Replies)
Discussion started by: Ravi S M
8 Replies

3. Shell Programming and Scripting

Help with Converting UTF-8 data to Unicode

How can I get an error when converting 3rd line, since it has invalid characters abcde a®cdée a�cd� Unicode for ® = ® é = é I used "iconv -f UTF-8 -t ISO-8859-15 in.txt > out.txt" (2 Replies)
Discussion started by: arunbs
2 Replies

4. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

5. Shell Programming and Scripting

Converting file format

My input file is Pipe delimited with 10 fields, I am trying to create a tab delimited output file with 6 fields from the provided input file. Below is sample data Input file abc||2|PIN|num||||www.123.com|abc@123.com| bcd||2|PIN|num|||||abc@123.com|... (3 Replies)
Discussion started by: pasupuleti81
3 Replies

6. Shell Programming and Scripting

converting config file to csv format

Hello, For 2 days now i've been searching for a solution to this. I am now beginning to doubt this is even possible. It's even harder when you don't know how to search for it. (which keywords generate enough relevancy etc..) I need to parse a config file to generate a CSV file in return. It... (7 Replies)
Discussion started by: zer0dvide
7 Replies

7. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

8. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

9. Shell Programming and Scripting

converting string to unicode

How can I can convert a string in a shell script that looks something like: ]] to unicode equivalent? thanks a lot, webtekie (1 Reply)
Discussion started by: webtekie
1 Replies

10. UNIX for Dummies Questions & Answers

Converting the File Creation Date to a new format

I need to capture a file's creation/modification date and time and convert this to a different format, whilst I can easily get the existing format from a ls -l | awk ' { print $......}' or a cut command I do not know how to convert it to a desired format? I should add that at present the ls -l... (1 Reply)
Discussion started by: barney_clough
1 Replies
Login or Register to Ask a Question