Help with change significant figure to normal figure command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with change significant figure to normal figure command
# 1  
Old 12-17-2013
Help with change significant figure to normal figure command

Hi,

Below is my input file:
Long list of significant figure
Code:
1.757E-4
7.51E-3
5.634E-5
.
.
.

Desired output file:
Code:
0.0001757
0.00751
0.00005634
.
.
.

Do anybody know how to change significant figure to normal figure through any command line language?

Thanks for any advice.

Last edited by perl_beginner; 12-17-2013 at 05:17 AM..
# 2  
Old 12-17-2013
A Python:
Code:
# cat num.py 
#!/usr/bin/env python
from decimal import Decimal

def main():
   numbers = '''1.757E-4
                7.51E-3
                5.634E-5'''

   numbers= [num.strip() for num  in numbers.split('\n')]
   for num in numbers:
       print "scientific: %s decimal: %s" % (num,str(Decimal(num)))

if __name__=="__main__":
    main()

Code:
#./num.py                                                                                          
scientific: 1.757E-4 decimal: 0.0001757
scientific: 7.51E-3 decimal: 0.00751
scientific: 5.634E-5 decimal: 0.00005634

# 3  
Old 12-17-2013
Hi Klashxx,

Thanks for your python script Smilie

Can I know that how can I let your python script to take my input file data as the input of your python script?

My input file is long list of significant figure which need to change to normal figure.
Sorry that I don't state clear in my post.

Thanks and looking forward to hear from you.
# 4  
Old 12-17-2013
Something like this:
Code:
# cat num.dat 
1.757E-4
7.51E-3
5.634E-5

Code:
# ./num.py num.dat                                                                                    
0.0001757
0.00751
0.00005634

Code:
# cat num.py                                                                                         
#!/usr/bin/env python

import sys
from decimal import Decimal

def main():
   try:
       f = open(sys.argv[1],'rb')
   except Exception,err:
       print err
       sys.exit(5)

   for number in f:
       print str(Decimal(number.strip()))
   

   f.close()
if __name__=="__main__":
    main()

# 5  
Old 12-17-2013
Code:
awk '{$1=$1+0}1' OFMT="%.8f" file
0.00017570
0.00751000
0.00005634

# 6  
Old 12-17-2013
Hi RudiC,

I just try with your awk command.
It return something as below:
Code:
awk '{$1=$1+0}1' OFMT="%.8f" file
0.0001757
0.00751
5.634e-05

The output result is different from what I expected.
Apart from that, is it possible your command work for something like "1.757E-100" and return "7.51E-3" as "0.00751" instead of "0.00751000".

Really thanks and sorry for troubling you.

---------- Post updated at 09:04 AM ---------- Previous update was at 08:57 AM ----------

Hi Klashxx,

I just try your python script with the data set.
But it return the following error message:
Code:
  File "./num.py", line 9
    except Exception,err:
    ^
IndentationError: unexpected indent

Is there something wrong with my python program?
Thanks for advice.
# 7  
Old 12-17-2013
What you show there is the "%.8g" behaviour. It will not fill the field length with 0 as "%f" does, but it will resort to e- notation if the exponent ist less than -4. I'm afraid that can't be modified; you may need to do string manipulations, then. Or use sth. like python etc..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Can't figure out the correct syntax for a command loading a webkit plugin

Hello, Using Bash on Mac OS X 10.7.5 (Lion). I downloaded a GrowlSafari plugin for Webkit from its GitHub page GitHub - uasi/growl-safari-bridge: GrowlSafariBridge enables arbitrary javascript (including Safari Extensions) to notify via Growl.. In the description it says that after installing for... (0 Replies)
Discussion started by: scrutinizerix
0 Replies

2. UNIX for Dummies Questions & Answers

Can't figure out why this repeats

#!/bin/sh while IFS=: read address port; do : ${port:=443} address=$address port=$port cd $f_location number=`grep "$address" thing.txt -A 1 | grep "addresses=" | cut -d'"' -f2` echo "$address,$port,$number,$answer" >>... (9 Replies)
Discussion started by: shade917
9 Replies

3. UNIX for Dummies Questions & Answers

Can't figure this one out --

I'm putting together a shell script while I'm learning UNIX -- just for myself. It's a little script that simply takes some vendor names and writes them to a file. So far I'm at the stage where the user enters the name of the file and places it in a folder called vendorlists: * ) touch... (5 Replies)
Discussion started by: Straitsfan
5 Replies

4. UNIX for Dummies Questions & Answers

Trying to figure out a log dump command

Ok so i'm relatively new at UNIX and I'm trying to figure out how to make a log dump command. My situation is a bit odd in that I'm always looking at customers boxes and as such I can't really do much to them. So everything I do in UNIX pretty much has to be a command I can type in by hand. I... (4 Replies)
Discussion started by: MrEddy
4 Replies

5. UNIX for Advanced & Expert Users

Can't figure out how this is working

I have two machines, each with a virtual interface, with the following configurations: Machine1: eth2 Link encap:Ethernet HWaddr 00:09:6B:19:E5:05 inet addr:172.16.0.201 Bcast:172.16.0.255 Mask:255.255.255.0 eth2:0 Link encap:Ethernet HWaddr 00:09:6B:19:E5:05 ... (0 Replies)
Discussion started by: druidmatrix
0 Replies

6. UNIX for Dummies Questions & Answers

How to figure out what each IP address is used for?

Hi, I have inherited a server at work that has one IP and two virtual IP's. It is live and I want to figure out what each IP is being used for. I thought of NETSTAT but I cannot figure out how to get it to list what each IP is listening for. ANy advice? (8 Replies)
Discussion started by: mojoman
8 Replies

7. IP Networking

How do I figure out the subnet?

Hi, How do I get subnet from this: 10.252.0.138/25 Tnx (2 Replies)
Discussion started by: mehrdad68
2 Replies

8. Shell Programming and Scripting

Cant figure out this..

Hi, I need a little help here. I am exporting user info from a PSQL database and everything is working with the exception of this: 10029008:dsAuthMethodStandard\:dsAuthClearText:classword:10029008:2004:10029008:10029008:/home/student/1002/90/08:10029008 It is putting a colon right before the... (1 Reply)
Discussion started by: Stud33
1 Replies

9. UNIX for Dummies Questions & Answers

figure it out

hi there i am new to this site and this linux and unix stuff so kind of plz help me out hoe to start the stuff.... (1 Reply)
Discussion started by: cool_dude
1 Replies

10. UNIX for Dummies Questions & Answers

i can not figure this out

I am having problems scripting in UNIX. I am currently attending school and for the first time I am being introduced to scripting. My problem is I am supposed to enhance the spell_check by adding a third optional argument. The third argument is to specify a list of words to be added to the... (1 Reply)
Discussion started by: steph
1 Replies
Login or Register to Ask a Question