Sponsored Content
Top Forums Shell Programming and Scripting How to format the output using float in awk{printf} Post 302313980 by angelarosh on Thursday 7th of May 2009 06:51:52 AM
Old 05-07-2009
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!!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk printf formatting using string format specifier.

Hi all, My simple AWK code does C = A - B If C can be a negative number, how awk printf formating handles it using string format specifier. Thanks in advance Kanu :confused: (9 Replies)
Discussion started by: kanu_pathak
9 Replies

2. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

4. Shell Programming and Scripting

Float number format problem -Awk

Here is the script I'm using awk '{print $1,"\t",(($2+$3)/2)-x,"\t",(($2+$3)/2)+x,"\t",$4,"\t",$5}' x=500 $1 I just want to make float numbers (red) like normal numbers (green) output cX 1.65107e+08 1.65108e+08 13 64.2 cX 165112764 165113764 27 ... (7 Replies)
Discussion started by: ruby_sgp
7 Replies

5. UNIX for Dummies Questions & Answers

awk printf in required format

Hi my awk variable $0 contains the below data Input file 000001 The Data 000002* The line 2 000003* The line3 output file Req 000001* The Data 000002** The line 2 000003** The line3 one * at column seven needs to be appended to the input lines, (5 Replies)
Discussion started by: rakeshkumar
5 Replies

6. Shell Programming and Scripting

awk printf format in columns

Hi all, i have written this script: awk -F';' ' BEGIN { printf "\n" printf "\n" printf "\n" printf "----------------------------------------------\n" print " For test " printf "----------------------------------------------\n" test_200 = 0 test_300 = 0 test_500 = 0 test_1000 = 0... (11 Replies)
Discussion started by: arrals_vl
11 Replies

7. Shell Programming and Scripting

printf format with awk

Hello Here is an easy one Data file 12345 (tab) Some text (tab) 53.432 23456 (tab) Some longer text (tab) 933.422 34567 (tab) Some different text (tab) 29.309 I need to awk these three tab-delimited columns so that the first two are unchanged (unformatted) and the third shows two decimal... (1 Reply)
Discussion started by: palex
1 Replies

8. Shell Programming and Scripting

Problems with awk printf, formatted output

Hi, i have a script, which is incomplete, am on my way developing it. Input 1,12,2012,IF_TB001 2,12,2012,3K3 3,Z56,00000,25,229,K900,00, ,3G3, ,USD, ,0000000000,000, , , , 550000000 3,Z56,00000,53,411,W225,00,000, , ,USD,OM170,0000000000,000, , , , -550000000 4,Z56,COUNT, 4,SUM LOC,... (19 Replies)
Discussion started by: selvankj
19 Replies

9. Shell Programming and Scripting

printf (awk,perl,shell) float rounding issue

Hi guys, could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?: $ uname -a Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
Discussion started by: elixir_sinari
9 Replies

10. Shell Programming and Scripting

Format output using awk

Hello all , need help with this ... Input File DEV % POOL 0CB4 FBA 2211300 81792 4 IE RAID-5(3+1) R5_EFD100_1 - - 1805376 82 IF RAID-1 M2_FC300_1 - ... (4 Replies)
Discussion started by: greycells
4 Replies
PRINTF(3S)																PRINTF(3S)

NAME
printf, fprintf, sprintf, vfprintf, vsprintf - formatted output conversion SYNOPSIS
#include <stdio.h> char *printf(format [, arg ] ... ) char *format; char *fprintf(stream, format [, arg ] ... ) FILE *stream; char *format; int sprintf(s, format [, arg ] ... ) char *s, *format; #include <varargs.h> char *vprintf(format, args) char *format; va_list args; char *vfprintf(stream, format, args) FILE *stream; char *format; va_list args; int vsprintf(s, format, args) char *s, *format; va_list args; DESCRIPTION
Printf places output on the standard output stream stdout. Fprintf places output on the named output stream. Sprintf places `output' in the string s, followed by the character `'. Alternate forms, in which the arguments have already been captured using the variable-length argument facilities of varargs(3), are available under the names vprintf, vfprintf, and vsprintf. Each of these functions converts, formats, and prints its arguments after the first under control of the first argument. The first argu- ment is a character string which contains two types of objects: plain characters, which are simply copied to the output stream, and conver- sion specifications, each of which causes conversion and printing of the next successive arg printf. Each conversion specification is introduced by the character %. The remainder of the conversion specification includes in the following order o a minus sign `-' which specifies left adjustment of the converted value in the indicated field; o an optional digit string specifying a field width; if the converted value has fewer characters than the field width it will be blank-padded on the left (or right, if the left-adjustment indicator has been given) to make up the field width; if the field width begins with a zero, zero-padding will be done instead of blank-padding; o an optional period, followed by an optional digit string giving a precision which specifies the number of digits to appear after the decimal point, for e- and f-conversion, or the maximum number of characters to be printed from a string; o the character l specifying that a following d, o, x, or u corresponds to a long integer arg; o a character which indicates the type of conversion to be applied. A field width or precision may be `*' instead of a digit string. In this case an integer arg supplies the field width or precision. The conversion characters and their meanings are dox The integer arg is converted to signed decimal, unsigned octal, or unsigned hexadecimal notation respectively. f The float or double arg is converted to decimal notation in the style `[-]ddd.ddd' where the number of d's after the decimal point is equal to the precision specification for the argument. If the precision is missing, 6 digits are given; if the precision is explicitly 0, no digits and no decimal point are printed. e The float or double arg is converted in the style `[-]d.ddde+-dd' where there is one digit before the decimal point and the number after is equal to the precision specification for the argument; when the precision is missing, 6 digits are produced. g The float or double arg is printed in style d, in style f, or in style e, whichever gives full precision in minimum space. c The character arg is printed. s Arg is taken to be a string (character pointer) and characters from the string are printed until a null character or until the num- ber of characters indicated by the precision specification is reached; however if the precision is 0 or missing all characters up to a null are printed. u The unsigned integer arg is converted to decimal and printed (the result will be in the range 0 through MAXUINT, where MAXUINT equals 4294967295 on a VAX-11 and 65535 on a PDP-11). % Print a `%'; no argument is converted. In no case does a non-existent or small field width cause truncation of a field; padding takes place only if the specified field width exceeds the actual width. Characters generated by printf are printed as by putc(3S). RETURN VALUE
The functions all return the number of characters printed, or -1 if an error occurred. EXAMPLES
To print a date and time in the form `Sunday, July 3, 10:02', where weekday and month are pointers to null-terminated strings: printf("%s, %s %d, %02d:%02d", weekday, month, day, hour, min); To print pi to 5 decimals: printf("pi = %.5f", 4*atan(1.0)); SEE ALSO
putc(3S), scanf(3S) BUGS
Very wide fields (>300 characters) fail. Only sprintf and vsprintf return a count of characters transferred. The functions still supports %D, %O, %U and %X. Do not use these formats, as they will be disappearing real soon now. 7th Edition August 10, 1988 PRINTF(3S)
All times are GMT -4. The time now is 06:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy