Converting Exponential values to decimals


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting Exponential values to decimals
# 1  
Old 07-01-2009
Converting Exponential values to decimals

Hi,

I have a number of large (500Mb) txt files in the following format:

Code:
  8.05475136E+05  9.69428147E+05  1 14  2968.00   3419.00     59.00   59 3.4028235E+38 2 w99-100
  8.05464719E+05  9.69435064E+05  1 14  2968.03   3418.50     60.00   60 3.4028235E+38 2 w99-100
  8.05454301E+05  9.69441981E+05  1 14  2968.05   3418.00     61.00   61 3.4028235E+38 2 w99-100
  8.05443884E+05  9.69448898E+05  1 14  2968.08   3417.50     62.00   62 3.4028235E+38 2 w99-100
  8.05433466E+05  9.69455815E+05  1 14  2968.11   3417.00     63.00   63 3.4028235E+38 2 w99-100
  8.05423048E+05  9.69462733E+05  1 14  2968.14   3416.50     64.00   64 3.4028235E+38 2 w99-100
  8.05412631E+05  9.69469650E+05  1 14  2968.16   3416.00     65.00   65 3.4028235E+38 2 w99-100
  8.05402213E+05  9.69476567E+05  1 14  2968.19   3415.50     66.00   66 3.4028235E+38 2 w99-100
  8.05391795E+05  9.69483484E+05  1 14  2968.22   3415.00     67.00   67 3.4028235E+38 2 w99-100
  8.05381378E+05  9.69490401E+05  1 14  2968.24   3414.50     68.00   68 3.4028235E+38 2 w99-100
  8.05370960E+05  9.69497318E+05  1 14  2968.27   3414.00     69.00   69 3.4028235E+38 2 w99-100

I would like toprint all the columns but convert the first two columns to decimals e.g. 8.05370960E+05 to 805370.960
Anything I have done has rounded the numbers to the nearest whole number e.g. 8.05370960E+05 to 805371

any help on this would be much appreciated.

Last edited by barrypitts; 07-01-2009 at 12:14 PM..
# 2  
Old 07-01-2009
Quote:
Originally Posted by barrypitts
...
I would like toprint all the columns but convert the first two columns to decimals e.g. 8.05370960E+05 to 805370.960
...
If losing the blank space formatting is ok with you, then one option could be:

Code:
$
$ awk '{printf("%.3f %.3f %s %s %s %s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}' data.txt
805475.136 969428.147 1 14 2968.00 3419.00 59.00 59 3.4028235E+38 2 w99-100
805464.719 969435.064 1 14 2968.03 3418.50 60.00 60 3.4028235E+38 2 w99-100
805454.301 969441.981 1 14 2968.05 3418.00 61.00 61 3.4028235E+38 2 w99-100
805443.884 969448.898 1 14 2968.08 3417.50 62.00 62 3.4028235E+38 2 w99-100
805433.466 969455.815 1 14 2968.11 3417.00 63.00 63 3.4028235E+38 2 w99-100
805423.048 969462.733 1 14 2968.14 3416.50 64.00 64 3.4028235E+38 2 w99-100
805412.631 969469.650 1 14 2968.16 3416.00 65.00 65 3.4028235E+38 2 w99-100
805402.213 969476.567 1 14 2968.19 3415.50 66.00 66 3.4028235E+38 2 w99-100
805391.795 969483.484 1 14 2968.22 3415.00 67.00 67 3.4028235E+38 2 w99-100
805381.378 969490.401 1 14 2968.24 3414.50 68.00 68 3.4028235E+38 2 w99-100
805370.960 969497.318 1 14 2968.27 3414.00 69.00 69 3.4028235E+38 2 w99-100
$
$

tyler_durden
# 3  
Old 07-01-2009
Cheers @tyler_durden for the quick response.
I've reviewed what I've been requested to do and figured that I really only need columns $1, $2, and $5 which are all the same length so losing the blank space formatting is okay at this point.

However keeping the space formatting is essential for most requests.

If anyone knows how this can be achieved I would be interested to hear it.

Cheers,
Barry
# 4  
Old 07-01-2009
Quote:
Originally Posted by barrypitts
However keeping the space formatting is essential for most requests.

If anyone knows how this can be achieved I would be interested to hear it.

Cheers,
Barry
Try this:
Code:
awk -F" |:" '
{$3=sprintf("%.3f", $3)}
{$5=sprintf("%.3f", $5)}
1' file

# 5  
Old 07-01-2009
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk -F" |:" '
{$3=sprintf("%.3f", $3)}
{$5=sprintf("%.3f", $5)}
1' file

That's perfect @Franklin52
Good job

Thanks very much @Franklin52 and @tyler_durden!!!
Barry
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk-Exponential Values

Hi Friends, My input Gene1 4.14887050399078e-49 Gene2 5.39999891278828e-10 Gene 2.22108326729483e-11 How do I change the above exponential values to normal values? Thanks (3 Replies)
Discussion started by: jacobs.smith
3 Replies

2. Shell Programming and Scripting

Trouble converting columns of integers to floating decimals

I have a document that has 7 columns. eg. $1 $2 $3 $4 $5 $6 $7 string string string string integer integer integer The 6th and 7th columns are a mix of integers and floating decimals (with 4 decimal places). I need to convert the last 2 columns so that all values are floating decimals w/4... (1 Reply)
Discussion started by: kadm
1 Replies

3. Shell Programming and Scripting

Converting odd values to even values(or vice-versa) located in a column

Hello All, I have a below data in a .csv file where all rows where col1 is A, col2 is odd numbers, similarly even numbers for all rows where col1 is B. Note that my data has some other columns(not shown here) too (around 100) after col2. Tool,Data A,1 A,3 A,5 .... so on B,2 B,4 .... ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

4. Shell Programming and Scripting

Converting filenames from julian day to yyyy-mm-dd and retrieving weekly mean values

Hi, I need help to convert the filenames of my 9-year daily files (1999-2007) from a julian day to yyyy-mm-dd format. my original files are patterned likes the ones below. 1999001.txt 1999002.txt 1999003.txt 1999004.txt ... 1999365.txt desired output: 19990101.txt 19990102.txt... (3 Replies)
Discussion started by: ida1215
3 Replies

5. Shell Programming and Scripting

The awk subtraction giving exponential values.Please help resolve it

Hi friends, I have a file list1 which has these 2 columns like 616449 0 434453 1 2151083 0 2226536 0 2132382 0 2136814 0 I have to put the result of col1 -col2 into another file list2 linewise. e.g. It gives the below result if use the below code: awk '{ print $1 - $2 }' list1 >... (2 Replies)
Discussion started by: kunwar
2 Replies

6. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies

7. Shell Programming and Scripting

Converting Column values to comma delimted single Row

I have a requirement in which i have to read a file which has multiple columns seperated by a pipe "|" from this i have to read each column values seperately and create a comma seperated row for the column and write to another file. eg: Input file: ColA ColB 1 2 2 x 3 y... (5 Replies)
Discussion started by: nvuradi
5 Replies

8. Shell Programming and Scripting

convert Regular decimals to Packed decimals

Hi, I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round. If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Discussion started by: mgirinath
2 Replies

9. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

10. Shell Programming and Scripting

Converting exponential values

Hi. Is there a way to convert a value outputted as(for example): 4.14486e+06 into a regular format: 4144860 I suppose in plain english i want to move the decimal point 6 places to the right. please??? (2 Replies)
Discussion started by: rleebife
2 Replies
Login or Register to Ask a Question