Double-precision result (awk)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double-precision result (awk)
# 1  
Old 05-10-2010
Double-precision result (awk)

hi,
I am a new awk user, now i want to change my result from

Code:
1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02
2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01
3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02

to
Code:
1 ca 0.02057422  -0.007179106  -0.005600872
2 o  0.02463722  -0.01554542    0.03110649
3 h  -0.01068047  0.01016889  -0.004088230



Any idea
Thanks
wanchem


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by radoulov; 05-10-2010 at 03:16 PM..
# 2  
Old 05-10-2010
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris:


Code:
awk '{
  gsub(/D-/,"E-")
  for (i = 2; ++i <= NF;) 
    $i = sprintf("%0.9f", $i)
      }-3
	' infile


Last edited by radoulov; 05-10-2010 at 03:47 PM..
# 3  
Old 05-10-2010
deleted.Smilie

Last edited by rdcwayx; 05-11-2010 at 09:25 AM..
# 4  
Old 05-11-2010
Thank you very much.

Smilie

wanchem
# 5  
Old 05-11-2010
Quote:
Originally Posted by rdcwayx
Code:
sed 's/D-[0-9]*//g' urfile

I believe the result will be different from mine Smilie

Last edited by radoulov; 05-11-2010 at 04:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Duplication | awk | result

Dear forum members, I want the script to count ALA as one (an example in quotes) and return an integer as 1 and not return 5 as an integer as it does now (look bash script). So how can I upgrade my script that it first checks or after finding all instances of ALA checks whether it is the same... (25 Replies)
Discussion started by: Aurimas
25 Replies

2. UNIX for Beginners Questions & Answers

Unexpected result from awk

Hello, Giving those commands: cat > myfile 1 2 3 ^D cat myfile | awk '{ s=s+$1 ; print s}' The output is: 1 3 6 It seems like this command iterates each time on a different row so $1 is the first field of each row.. But what caused it to refer to each row ?. What I mean... (3 Replies)
Discussion started by: uniran
3 Replies

3. Emergency UNIX and Linux Support

How to take awk result out (piping to other program)?

Hi! all here is my code which is working fine no errors but I want to know how to take result and input to other program awk 'FNR==1{i++}{LC=NR} {for(k=1; k<=NF; k++) A=$k} END{for (i=1;i<=LC;i++) { for(j=1;j<=LC;j++) if(A=='$UID' && A>='$MX'+A &&... (7 Replies)
Discussion started by: Akshay Hegde
7 Replies

4. UNIX for Advanced & Expert Users

awk calculated with amazing result

I don't the following why ?:confused: $ awk 'BEGIN{printf "%.40f\n",(0.33*3)}' 0.9899999999999999911182158029987476766109 $ awk 'BEGIN{printf "%.4f\n",(0.33*3)}' 0.9900 (0 Replies)
Discussion started by: saloman
0 Replies

5. UNIX for Dummies Questions & Answers

awk calculated with amazing result

I don't the following why ?:confused: $ awk 'BEGIN{printf "%.40f\n",(0.33*3)}' 0.9899999999999999911182158029987476766109 $ awk 'BEGIN{printf "%.4f\n",(0.33*3)}' 0.9900 (0 Replies)
Discussion started by: saloman
0 Replies

6. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

7. Shell Programming and Scripting

conflict: "for" loops and double precision numbers

Hi folk, Hope you enjoy the summer. I am stock after one day working, the problems are the following: 1) I want to write a for loop in a shell script code that has a double precision step as: #!/bin/bash START=0.00001 STOP=0.001 for((i = START ; i< STOP ; i=2*i)) do echo "$i"... (1 Reply)
Discussion started by: habib
1 Replies

8. HP-UX

awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print. .... | awk '{print $0}' I would like it to print the date right before $0, so something like (this doesn't work though) .... | awk '{print date $0}' (4 Replies)
Discussion started by: IMTheNachoMan
4 Replies

9. Shell Programming and Scripting

Elimincating double result when using find and grep

Hi, i am using the command find . -exec grep -i "sometexttofoundinfiles" '{}' \; -print The problem with this command is it prints the path of file i want twice. I did try the "-q" option of the grep command. It generates an error "invalid option". i guess the shell i am using... (1 Reply)
Discussion started by: silas.john
1 Replies

10. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies
Login or Register to Ask a Question