The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Converting Column values to comma delimted single Row nvuradi Shell Programming and Scripting 5 01-23-2009 01:24 AM
convert Regular decimals to Packed decimals mgirinath Shell Programming and Scripting 2 09-20-2008 09:27 AM
Conversion of Exponential to numeric in awk- not correct output ssunda6 Shell Programming and Scripting 3 09-19-2008 01:36 AM
Converting Binary decimal coded values to Ascii Values gaur.deepti UNIX for Advanced & Expert Users 3 04-02-2008 12:33 PM
Converting exponential values rleebife Shell Programming and Scripting 2 08-02-2007 11:59 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2009
barrypitts barrypitts is offline
Registered User
  
 

Join Date: Jul 2009
Location: Dublin, Irelnad
Posts: 3
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 11:14 AM..
  #2 (permalink)  
Old 07-01-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 517
Quote:
Originally Posted by barrypitts View Post
...
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 (permalink)  
Old 07-01-2009
barrypitts barrypitts is offline
Registered User
  
 

Join Date: Jul 2009
Location: Dublin, Irelnad
Posts: 3
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 (permalink)  
Old 07-01-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Originally Posted by barrypitts View Post
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 (permalink)  
Old 07-01-2009
barrypitts barrypitts is offline
Registered User
  
 

Join Date: Jul 2009
Location: Dublin, Irelnad
Posts: 3
Quote:
Originally Posted by Franklin52 View Post
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
Reply

Bookmarks

Tags
awk, convert, numeric

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0