Converting CSV to ascii format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting CSV to ascii format
# 1  
Old 01-26-2012
Converting CSV to ascii format

Hej All,

I have a file like this which is a comma dilimited:

input:

Code:
6000318,-263.011520678,-59.05869872409,587.67924868792
6000319,-265.6996842902,-50.24902479999,590.65693082607
6000320,-238.1333898366,-288.801232595,633.75332173496
6000321,-238.0466734864,-290.7217772662,623.60922656308
6000322,-237.8308371431,-291.5919339073,613.85206092817
6000323,-237.6900817526,-281.0114436973,613.12390164076
6000324,-238.0551925104,-270.3998913848,611.9122076891
6000325,-237.7062987535,-279.5289804322,623.0771105491
6000326,-237.7545552067,-276.8706392,633.45978643332
6000327,-237.8064447543,-268.6579344511,621.6766956356
6000328,-237.8039226993,-273.3144349458,643.99521886477
6000329,-237.7138565922,-265.9359211197,632.01000386728
6000330,-237.699411038,-260.1218696827,643.38639576584
6000331,-238.037499527,-252.9476448912,636.14668632827
6000332,-238.5361360976,-243.2849203525,637.19146375821


and want to convert it to an ascii file, which the first column is 8bit and other columns are 16 bit and the output would be like this:

output:

Code:
 6000318  -263.011520678 -59.05869872409 587.67924868792
 6000319 -265.6996842902 -50.24902479999 590.65693082607
 6000320 -238.1333898366  -288.801232595 633.75332173496
 6000321 -238.0466734864 -290.7217772662 623.60922656308
 6000322 -237.8308371431 -291.5919339073 613.85206092817
 6000323 -237.6900817526 -281.0114436973 613.12390164076
 6000324 -238.0551925104 -270.3998913848  611.9122076891
 6000325 -237.7062987535 -279.5289804322  623.0771105491
 6000326 -237.7545552067    -276.8706392 633.45978643332
 6000327 -237.8064447543 -268.6579344511  621.6766956356
 6000328 -237.8039226993 -273.3144349458 643.99521886477
 6000329 -237.7138565922 -265.9359211197 632.01000386728
 6000330  -237.699411038 -260.1218696827 643.38639576584
 6000331  -238.037499527 -252.9476448912 636.14668632827
 6000332 -238.5361360976 -243.2849203525 637.19146375821

How could I do this conversion with bash scripting?

tnx
# 2  
Old 01-26-2012
They both look like ASCII text to me. The only difference I see is the change from comma delimiting to space delimiting.

If you're referring to different character encodings, it makes no sense to mix different encodings in the same file and you haven't told us which 8-bit and which 16-bit encodings you want, either.
# 3  
Old 01-26-2012
Quote:
Originally Posted by Corona688
They both look like ASCII text to me. The only difference I see is the change from comma delimiting to space delimiting.

If you're referring to different character encodings, it makes no sense to mix different encodings in the same file and you haven't told us which 8-bit and which 16-bit encodings you want, either.
the output file does not have comma the first column of numbers would occupy just first 8 columns of the output file and the rest of column of numbers would go to sections of the output file which each of them has 16 column space of the output file, so the output file has 8+16+16+16 columns which each number should stay in specific section.
# 4  
Old 01-26-2012
I think you meant bytes, not bits Smilie

Code:
awk -F, '{printf("%8s%16s%16s%16s\n",$1,$2,$3,$4) }' file

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 01-26-2012
Quote:
Originally Posted by Corona688
I think you meant bytes, not bits Smilie

Code:
awk -F, '{printf("%8s%16s%16s%16s\n",$1,$2,$3,$4) }' file

tnx,

should I use it like this?

Code:
awk -F, '{printf("%8s%16s%16s%16s\n",$1,$2,$3,$4) }' input > output

# 6  
Old 01-26-2012
Please note that CSV is a file format not a file encoding like ASCII, EBCDIC, UTF-8, etc... There is a big difference.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting csv to html format

Below is the code I have - How can I convert the data in the csv into 3 tables in html. instead of 1 table. Attached is the format I am getting. (1 Reply)
Discussion started by: archana25
1 Replies

2. Shell Programming and Scripting

Format problem while converting text file to csv

Hi , I need a help in following scenario.I tried searching in google but couldn't able to find the exact answer. Sorry if i am re-posting already answered query. While i am trying to convert into log file into csv i couldn't able to get the format which i am looking for. I converted file... (4 Replies)
Discussion started by: varmas424
4 Replies

3. Shell Programming and Scripting

Converting hex to ascii/decimal

I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal. Data Example: The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the... (16 Replies)
Discussion started by: Shiftkey
16 Replies

4. UNIX for Advanced & Expert Users

Cutting two colums and converting them to ascii (.txt) format

Hello Gurus, I have a file in which two columns contains binary data i want to cut those two binary columns convert them to ascii and process the file. i tried using cut command..i am able to cut but how can i convert them from binary to ascii and paste them in their original position. ... (1 Reply)
Discussion started by: mora
1 Replies

5. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 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. Shell Programming and Scripting

converting text to csv format

I am trying to check each line and based on first two digits, the comma needs to be place. I checked in the earlier post where the text is converted to csv with a tab delimited. Here is the test file that needs to be changed to csv 11 051701 22 051701 330123405170105170112345... (13 Replies)
Discussion started by: gthokala
13 Replies

8. UNIX for Advanced & Expert Users

Converting ASCII to Binary mode

Dear All, Business Users are transfering ( FTP ) a CSV file into the IBM AIX box with transfer mode as ASCII. But I want to convert the CSV file from ASCII mode into binary mode, as my script expects file in binary mode. Is it possible to do through Unix commands? Thanks in Advance, RK (1 Reply)
Discussion started by: srajeshmca
1 Replies

9. UNIX for Advanced & Expert Users

converting Opentype to ASCII (for groff)

I'm trying to convert different versions of helvetica neue from Opentype to ascii so that groff can use them in conjunction with VI (I believe everything is printed to postscript after). Ultimately i need to be able to use these specific helvetica fonts in VI, but in order to do this i must convert... (1 Reply)
Discussion started by: abby
1 Replies

10. Programming

converting hex to ascii

Hi everyone! I was wondering if anyone knows how to change hex code back into ascii. when i process a form: " / " turn to " %2F " " @ " turns to " %40 " " ' " turns to " %27 " " ( " turns to " %28 " " ) " turns to " %29 " this is my code so far: order.txt thanks, primal p.s.... (1 Reply)
Discussion started by: primal
1 Replies
Login or Register to Ask a Question