Converting CSV to ascii format

Hej All,

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

input:

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:

 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

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.

I think you meant bytes, not bits :slight_smile:

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

tnx,

should I use it like this?

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

Please note that CSV is a file format not a file encoding like ASCII, EBCDIC, UTF-8, etc... There is a big difference.