How to convert file in Unix


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers How to convert file in Unix
# 1  
Old 10-23-2011
How to convert file in Unix

we have a file that shows encoding as small-endian (in NotePad+). I can not read this file in my program. If I change it to ANSI (again in Notepad+) and save it, I am able to read it in my program.
Can I use the iconv function to change this file to ANSI ?
Thanks in advance for your help.
# 2  
Old 10-23-2011
First you need to list code sets in the internal table
With the following command.
Code:
$iconv -l

or
Code:
$iconv -v

then select the encodings you intend to convert to
Code:
$iconv [-sc] -f oldset -t newset [file ...]

# 3  
Old 10-23-2011
iconv

Ok,
Code:
iconv -l (or -v) produces the following message;
iconv: usage: iconv -f fromcode -t tocoe [file..]
 
$iconv -l   produces;
sh: iconv: parameter not set

I appreciate your patience - This is my first time on a Unix box (if you haven't already noticed)

Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 10-24-2011 at 12:18 PM.. Reason: code tags, see PM
# 4  
Old 10-24-2011
What flavor of UNIX do you have?
If AIX then the iconv command uses the LOCPATH environment variable to search for code-set converters of the form iconv/FromCodeSet_ToCodeSet. The default value of LOCPATH is /usr/lib/nls/loc.

Run the following
Code:
$export LOCPATH=/usr/lib/nls/loc
$iconv -l

# 5  
Old 10-24-2011
config.iconv

This is an HP Unix system. I downloaded the config.iconv to see what codesets were supported.
Using Notepad+ to check Encoding - it shows it as 'UCS-2 - Little Endian'.
So - I'm trying to understand what character encode UCS-2 is -

And then looking at config.iconv, I'm trying to understand the correlation;
(sample below) - thanks
Code:
# UTF-8 to HP supported codesets
#
utf8 roma8 ucs2=roma8 lutf8hp.sl -
utf8 iso81 ucs2=iso81 lutf8hp.sl -
utf8 iso82 ucs2=iso82 lutf8hp.sl -
utf8 iso85 ucs2=iso85 lutf8hp.sl -
utf8 iso86 ucs2=iso86 lutf8hp.sl -
utf8 iso87 ucs2=iso87 lutf8hp.sl -
utf8 iso88 ucs2=iso88 lutf8hp.sl -
utf8 iso89 ucs2=iso89 lutf8hp.sl -
utf8 iso815 ucs2=iso815 lutf8hp.sl -
utf8 thai8 ucs2=thai8 lutf8hp.sl -
utf8 eucJP ucs2=eucJP lutf8hp.sl -
utf8 sjis ucs2=sjis lutf8hp.sl -
utf8 eucTW ucs2=eucTW lutf8hp.sl -
utf8 big5 ucs2=big5 lutf8hp.sl -
utf8 roc15 ucs2=roc15 lutf8hp.sl -
utf8 kore5 ucs2=eucKR lutf8hp.sl -
utf8 hp15CN ucs2=hp15CN lutf8hp.sl -
utf8    hkbig5  ucs2=hkbig5     lutf8hp.sl      -
utf8    gb18030 ucs2=gb18030    lutf8hp.sl      -

Moderator's Comments:
Mod Comment Please use code tags <- click the link!


---------- Post updated at 11:21 AM ---------- Previous update was at 10:44 AM ----------

Looks like it's
Code:
iconv -f usc2 -t iso81 (old-file) > (new-file)

For my file

(I'll test a little later)

Thanks for your help

Last edited by zaxxon; 10-24-2011 at 12:25 PM.. Reason: code tags, see PM
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Shell Programming and Scripting

Convert UNIX timestamp to readable format in the file

Hello I have a file : file1.txt with the below contents : 237176 test1 test2 1442149024 237138 test3 test4 1442121300 237171 test5 test7 1442112823 237145 test9 test10 1442109600 In the above file fourth field represents the timestamp in Unix format. I found a command which converts... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

Need to convert delimited text file in UNIX to an Excel file

Dear Users , Need to convert delimited text files in UNix server to an Excel file and move the excel file to Windows environment. Am trying to automate the whole process. Can anyone share the ideas,if they have done similar ones before...Thanks -Meera (1 Reply)
Discussion started by: meerakrish
1 Replies

5. Shell Programming and Scripting

Convert to UTF8 File - Unix

All, I have several *.dat files which is created in windows (ANSI Endoing) Or PC File format, once I copy those files to unix. How can I convert those file to utf8 encoding ? I tired iconv, it says not supported Please help Thanks - S (5 Replies)
Discussion started by: Shanks
5 Replies

6. Shell Programming and Scripting

Convert MS Excel file to Tab limiter file in UNIX

Hi, We have a couple of ms excel files in unix server.We need convert the excel files to files TAB limiter format file with using unix script. Could you please advise on this (2 Replies)
Discussion started by: koti_rama
2 Replies

7. Shell Programming and Scripting

How to convert a excel file to a .csv file from unix script

Hi I have a excel file in unix machine and have to convert it into a .csv file.I have to do this from a unix script.How do we do this? Thanks Abhinav (3 Replies)
Discussion started by: akashtcs
3 Replies

8. Shell Programming and Scripting

How to convert a .log file into .txt file under unix??

Hi Friends, I have a .log file generated from a tool(Windows PC) which can be opened using a notepad, but when I tried to view the file in unix (cygwin on my laptop) the file type is showing as binary file, So I am unable to process the file. I need to extract some of the selected text... (3 Replies)
Discussion started by: ks_reddy
3 Replies

9. UNIX for Dummies Questions & Answers

How to convert Unix executable file to Tiff

Hi, I know nothing about Unix. Recently received image files from a client. Mac sees it as a Unix executable file. How do I convert these files to Tiff? Thanks for helping. (1 Reply)
Discussion started by: Pet Teoh
1 Replies

10. UNIX for Dummies Questions & Answers

How to convert binary Unix file to text

Hi all, I have a print control file (dflt) for Oracle which is in binary. As I am going to develope an application in Window environment, I would like to reference the dflt file. But it is in binary format and I cannot access it. Anyone can suggest me how to convert the file into text or... (5 Replies)
Discussion started by: user12345
5 Replies
Login or Register to Ask a Question