The UNIX and Linux Forums  

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
Help please...output problems with printf. pwanda UNIX for Advanced & Expert Users 3 10-19-2008 08:30 PM
awk printf formatting using string format specifier. kanu_pathak Shell Programming and Scripting 9 08-25-2008 08:51 PM
How do I stop printf output from going into seperate txt files chrchcol Shell Programming and Scripting 12 07-26-2006 10:08 PM
printf format laila63 Shell Programming and Scripting 3 07-16-2004 01:29 PM
fixed-width printf() output on an XmList on Solaris trido High Level Programming 0 11-20-2002 05:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-06-2009
angelarosh angelarosh is offline
Registered User
  
 

Join Date: May 2009
Posts: 13
Arrow How to format the output using float in awk{printf}

Hi

I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv.

The sample data that is available in this field is given below
220731.7100000000000000

When i tried using this command
cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}'

I get the output as -220731.7099999999991269
but i need the output as -220731.7100000000000000

Plz let me know on the format that i should be using to retreive the desired output.
Thanks!!!
  #2 (permalink)  
Old 05-06-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
awk '{printf("%23.16f\n", sprintf("%.2f", $6-1))}' xxx_yyy.hrv

  #3 (permalink)  
Old 05-07-2009
angelarosh angelarosh is offline
Registered User
  
 

Join Date: May 2009
Posts: 13
Hi vgersh99!!!

I tried with command that you've given
awk '{printf("%23.16f\n", sprintf("%.2f", $6-1))}' xxx_yyy.hrv | head -5 | tail -1

but i get the output as
220730.7099999999991269

but i need the output to be
-220731.7100000000000000

My requirement is to multiply the 6th field value with -1, and my pbm is the value after the decimal point gets modified when it is multiplied.

Plz let me know for any other possibilities also.

Thanks!!!
  #4 (permalink)  
Old 05-07-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk '{printf("%.2f%.14d\n", $6 * -1, 0)}' xxx_yyy.hrv

  #5 (permalink)  
Old 05-07-2009
angelarosh angelarosh is offline
Registered User
  
 

Join Date: May 2009
Posts: 13
It Worked !!!
Thanks a lot!!!
Closed Thread

Bookmarks

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 07:02 AM.


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